pointfreeco / swift-snapshot-testing

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

Trait Overrides support for iOS 17 #798

Open AllDmeat opened 10 months ago

AllDmeat commented 10 months ago

Describe the bug We were using SnapshotTesting for testing Dynamic Type with views being autosized using systemLayoutSizeFitting. Similar strategy can be found at https://github.com/pointfreeco/swift-snapshot-testing/pull/727.

This year Apple updated trait system at iOS 17. You can learn more at WWDC'23 session Unleash the UIKit trait system. Traits are now applied only after the view has been added to the view hierarchy, rather than before.

At the same time, the SnapshotTesting library continues to request the view size before it is added to the hierarchy. Because of these two behaviors, we have a conflict and cannot test Dynamic Type with autosizing views.

To Reproduce SnapshotDemo.zip

Expected behavior Size is being requested after the view is added to the view hierarchy and all traitOverrides are applied.

Environment