How do you mock/stub navigationController in a test case when you're testing a view controller? I am getting a runtime exception because its nil in my UIViewController when running tests. You can't set it directly because it's read-only. I'm using Swift 2.2, and XCTest.
As described in the comment above, this is possible by instantiating a UINavigationController and adding the view controller you are trying to test to its view array. Code:
let navigationController = UINavigationController()
let yourViewController = YourUIViewController()
navigationController.viewControllers = [yourViewController]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With