pointfreeco / swift-snapshot-testing

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

Possible Strategy to use SwiftUI snapshots on a mac with ImageRenderer #888

Open doozMen opened 2 months ago

doozMen commented 2 months ago

assertSnapshot(of: Text("Hello"), as: .image) will not compile or give runtime crash due to missing frame

I added a test that runs on macOS and IOS and produces a snapshot. It uses ImageRenderer which is only available as of iOS 16 and also on macOS it requires at least 13. So using it is not a general solution. It however solves/bypasses the issues I had with making a simple snaphot of a swiftUI view.

I'm not sure this is a good solution or more of a workaround? But I think it might document a problem and could be a strategy for some?

Might relate to issue https://github.com/pointfreeco/swift-snapshot-testing/issues/428, https://github.com/pointfreeco/swift-snapshot-testing/pull/533