How to test if a UIControlEvents has been fired
问题 I have a library implementing a custom UIControl with a method which would fire a .valueChanged event when called. I would like to test the method for that behavior. My custom control: class MyControl: UIControl { func fire() { sendActions(for: .valueChanged) } } And the test: import XCTest class ControlEventObserver: NSObject { var expectation: XCTestExpectation! init(expectation anExpectation: XCTestExpectation) { expectation = anExpectation } func observe() { expectation.fulfill() } }