Created
June 15, 2018 01:28
-
-
Save surpher/f09160313137711c39ff9f6a87b6df3a to your computer and use it in GitHub Desktop.
XCTest dismiss got called tapping UINavigationBar button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewControllerTests: XCTestCase { | |
func testDismissGetsCalled() { | |
let sut = MockViewController() | |
sut.loadViewIfNeeded() | |
guard let dismissButton = sut.navigationItem.leftBarButtonItem else { XCTFail("should have a dismiss button"); return } | |
guard let action = dismissButton.action else { XCTFail("dismiss button should have an action"); return } | |
sut.performSelector(onMainThread: action, with: dismissButton, waitUntilDone: true) | |
XCTAssertTrue(sut.dismissedGotCalled) | |
} | |
} | |
extension ViewControllerTests { | |
class MockViewController: ViewController { | |
var dismissedGotCalled = false | |
var completionHandler: (() -> Void)? | |
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { | |
dismissedGotCalled = true | |
completionHandler?() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment