I'm trying to unit test a function which presents a view outside a viewController:
public func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
let alertWindow = UIWindow(frame: UIScreen.main.bounds)
alertWindow.rootViewController = UIViewController()
alertWindow.windowLevel = UIWindowLevelAlert + 1;
alertWindow.makeKeyAndVisible()
alertWindow.rootViewController?.present(self, animated: animated, completion: completion)
}
so far all I can think about how to unit test it is like this:
func test_presentInOwnWindow () {
let presented = sut.presentInOwnWindow(animated: true) {}
XCTAssertNotNil(presented)
}
I've tried passing a bool for the completion block :
completion: ((Bool) -> Void)
but since its invoking the completion for:
rootViewController?.present
I get the error:
Cannot convert value of type '((Bool) -> Void)?' to expected argument type '(() -> Void)?'
Any idea how to unit test the function properly?