"No image could be generated for this view as its size was zero" for a SwiftUI view
mpivchev opened this issue · comments
Milen Pivchev commented
Describe the bug
This is the image that is generated from trying to snapshot a SwiftUI view:
I tested multiple views and this happens for all of them.
To Reproduce
- Write test function for a SwiftUI view
- Generated image is an error
This is the code in my test:
let contentView = NCCapabilitiesView(capabilitiesStatus: getCapabilitiesViewOOForPreview())
assertSnapshot(matching: contentView, as: .image)
The view shows just fine on Xcode preview and I call it the same way:
static var previews: some View {
NCCapabilitiesView(capabilitiesStatus: getCapabilitiesViewOOForPreview())
}
The only way I can fix this is by specifying the frame size myself:
NCCapabilitiesView(capabilitiesStatus: getCapabilitiesViewOOForPreview()).frame(width: 300, height: 300)
I don't think this is how it's supposed to work however.
Expected behavior
The snapshot image should generate properly from the SwiftUI view.
Environment
- swift-snapshot-testing version 1.11.0
- Xcode 14.3
- Swift 5
- OS: iOS 16.4
Stamatios Stroumpis commented
You could check this workaround: #368 (comment)