swift-snapshot-testing icon indicating copy to clipboard operation
swift-snapshot-testing copied to clipboard

Crashes if I add my view to UIWindow before recording snapshot

Open tahirmt opened this issue 3 years ago • 1 comments

Describe the bug If I try to run a snapshot test for a view controller but by adding it into a window myself, it causes a crash

To Reproduce

// And/or enter code that reproduces the behavior here.
import SnapshotTesting
import XCTest

class MyViewControllerTests: XCTestCase {
    func testMyViewController() {
        let vc = UIViewController()
        let window = UIWindow()
        window.rootViewController = vc
        window.isHidden = false

        assertSnapshot(matching: window, as: .image)
    }
}

Expected behavior The window should be recorded as any other view does

Environment

  • swift-snapshot-testing version 1.9.0
  • Xcode 13.2.1
  • Swift 5.5
  • OS: iOS 15

Additional context

This is the console messages

Newly-taken snapshot does not match reference.
Test Case '-[snapshottoeventuallyTests.MyViewControllerTests testMyViewController]' failed (1.089 seconds).
Test Suite 'MyViewControllerTests' failed at 2022-03-30 15:23:21.256.
	 Executed 1 test, with 1 failure (0 unexpected) in 1.089 (1.090) seconds
Test Suite 'snapshottoeventuallyTests.xctest' failed at 2022-03-30 15:23:21.257.
	 Executed 2 tests, with 1 failure (0 unexpected) in 1.107 (1.114) seconds
Test Suite 'All tests' failed at 2022-03-30 15:23:21.258.
	 Executed 2 tests, with 1 failure (0 unexpected) in 1.107 (1.119) seconds
2022-03-30 15:23:21.262036-0400 snapshottoeventually[86546:2233788] *** -[UIWindowLayer isHidden]: message sent to deallocated instance 0x6040004b1210

tahirmt avatar Mar 30 '22 19:03 tahirmt