Snapshotting.wait on UIViewController does not work if view is not referenced
JustasL opened this issue · 3 comments
JustasL commented
Describe the bug
Snapshotting.wait
does not work unless view
value is read
I've created a demo repo, that's very simple, contains framework, snapshot test target
To Reproduce
Demo repo: https://github.com/JustasL/DelayedSnapshotingDemo
Run testDelayedSnapshoting
in my DemoUIKitTests
The generated UIViewController snapshot screenshot will have a red background
class DemoViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.view.backgroundColor = .green
}
}
}
final class DemoUIKitTests: XCTestCase {
func testDelayedSnapshoting() throws {
let vc = DemoViewController()
assertSnapshot(
matching: vc,
as: .wait(for: 2, on: .image(on: .iPhone13))
)
}
}
Expected behavior
While I would expect to see a green background, due to delay in viewDidLoad
and wait
One work-a-round for this issue is to call
let _ = vc.view
Before calling assertSnapshot
, but then if we have UI setup logic in viewWillAppear
with delay, the assertSnapshot
method breaks again
Environment
- swift-snapshot-testing version 1.11.0
- Xcode 14.3