Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No image could be generated for this view as its size was zero" for a SwiftUI view #738

Open
mpivchev opened this issue Jun 7, 2023 · 1 comment

Comments

@mpivchev
Copy link

mpivchev commented Jun 7, 2023

Describe the bug
This is the image that is generated from trying to snapshot a SwiftUI view:

image

I tested multiple views and this happens for all of them.

To Reproduce

  1. Write test function for a SwiftUI view
  2. 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
@stamceidas
Copy link

stamceidas commented Sep 11, 2023

You could check this workaround: #368 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants