Skip to content

Commit f86e932

Browse files
Add tests for viewDidLoad
1 parent 812999e commit f86e932

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎Tests/UICoreTests/ViewControllerTests.swift

+41
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,47 @@ final class ViewControllerTests: XCTestCase {
6666

6767
XCTAssert(sut.next === expectedResult)
6868
}
69+
70+
func testViewDidLoadMethodCalledAfterLazyViewLoad() {
71+
let sut = MockViewController()
72+
73+
let expectation = self.expectation(description: "viewDidLoad should be called")
74+
75+
sut.viewDidLoadBlock = {
76+
expectation.fulfill()
77+
}
78+
79+
_ = sut.view
80+
81+
wait(for: [expectation], timeout: 0.1)
82+
}
83+
84+
func testViewDidLoadMethodCalledAfterManualViewLoad() {
85+
let sut = MockViewController()
86+
87+
let expectation = self.expectation(description: "viewDidLoad should be called")
88+
89+
sut.viewDidLoadBlock = {
90+
expectation.fulfill()
91+
}
92+
93+
sut.loadViewIfNeeded()
94+
95+
wait(for: [expectation], timeout: 0.1)
96+
}
97+
98+
func testViewDidLoadMethodNotCalledIfViewNotLoaded() {
99+
let sut = MockViewController()
100+
101+
let expectation = self.expectation(description: "viewDidLoad should not be called")
102+
expectation.isInverted = true
103+
104+
sut.viewDidLoadBlock = {
105+
expectation.fulfill()
106+
}
107+
108+
wait(for: [expectation], timeout: 0.1)
109+
}
69110
}
70111

71112
final class MockViewController: ViewController {

0 commit comments

Comments
 (0)