Issue #670
To test for viewWillDisappear
during UINavigationController
popViewController
in unit test, we need to simulate UIWindow
so view appearance works.
final class PopTests: XCTestCase {
func testPop() {
let window = UIWindow(frame: UIScreen.main.bounds)
let navigationController = UINavigationController()
window.rootViewController = navigationController
let viewController = DetailViewController()
navigationController.viewControllers = [
UIViewController(),
viewController
]
window.makeKeyAndVisible()
let expectation = XCTestExpectation()
navigationController.popViewController(animated: false)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
XCTAssertTrue(viewController.wasDismissed)
expectation.fulfill()
}
wait(for: [expectation], timeout: 1)
}
}
class DetailViewController: UIViewController {
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if isMovingFromParent {
wasDismissed = true
}
}
}
Updated at 2020-08-14 07:30:07