.recursiveDescription doesn't work properly for SwiftUI views
severeduck opened this issue · 2 comments
Describe the bug
When view hierarchy is created, a Swift UI identifier doesn't get purged. It causes unit test to fail because ids always mismatch. In my case it's
−<_TtGC7SwiftUI14_UIHostingViewGVS_15ModifiedContentVC20SnapshotTestingTests20SnapshotTestingTestsP10$10e77fe206MyViewGVS_19_BackgroundModifierVS_5Color___; frame = (0 0; 500 500); gestureRecognizers = <NSArray>; layer = <CALayer>>
+<_TtGC7SwiftUI14_UIHostingViewGVS_15ModifiedContentVC20SnapshotTestingTests20SnapshotTestingTestsP10$10724fe206MyViewGVS_19_BackgroundModifierVS_5Color___; frame = (0 0; 500 500); gestureRecognizers = <NSArray>; layer = <CALayer>>
$10e77fe206
$10724fe206
I found the func purgePointers(_ string: String) -> String {
but it doesn't seem to be possible to fix it for me without modifying the code inside the library which I would really like to avoid. Creating a new strategy also doesn't seem to help in this scenario.
To Reproduce
swift-snapshot-testing-main 2.zip
You can add the following code inside the func testSwiftUIView_iOS()
at the bottom of the function body (or download the zip):
// ...
let hostingVC = UIHostingController(rootView: view)
assertSnapshot(matching: hostingVC.view, as: .recursiveDescription(size: .init(width: 500, height: 500)))
Expected behavior
The test should succeed.
Environment
- swift-snapshot-testing version 1.10.0
- Xcode 14.0.1
- Swift 5.7
- OS: iOS 13, iOS 16 - doesn't really matter
Hey, we are facing the same problem. Is there any update regarding this issue?
+1