pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.73k stars 566 forks source link

"Unbalanced calls to begin/end appearance transitions" when creating initial snapshot #538

Open dmeehan1968 opened 2 years ago

dmeehan1968 commented 2 years ago

Xcode console emits the message:

Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x7fa551921b50>

when this line is executed, when there is no existing snapshot on the disk (i.e. first run).

https://github.com/pointfreeco/swift-snapshot-testing/blob/09520c3523ad5e7ccb8507f1b8cc28d74d7a2832/Sources/SnapshotTesting/AssertSnapshot.swift#L52

I'm using the following assertion when this happens:

        assertSnapshot(as: .image(layout: .sizeThatFits, traits: .init(userInterfaceStyle: .light))) {
            NewReminderButton()
                .fixedSize()
        }
markst commented 2 years ago

Definitely happening here: https://github.com/pointfreeco/swift-snapshot-testing/blob/main/Sources/SnapshotTesting/Common/View.swift#L898

Shame that disabling animations doesn't resolve:

UIView.setAnimationsEnabled(false)
markst commented 1 year ago

oops think View.swift has been modified since my last comment.

anyway it's something to do with the .beginAppearanceTransition & endAppearanceTransition routine which is triggering this Unbalanced calls output... I'd need to spend a bit of time to rewrite the add(traits to clean it up.

hello-im-szymon commented 1 year ago

Here's an old PR that fixes it: https://github.com/pointfreeco/swift-snapshot-testing/pull/528. May need an update for the current base branch