1

I am following this page in creating a wrapped HStack. However, the HStack asynchronously calculates its height, which means my snapshot testing become really funky. I looked at this episode on asynchronous snapshot testing but it wasn't too clear/helpful.

Could someone help shed light on how to use the SwiftUI Snapshot Testing Library (https://github.com/pointfreeco/swift-snapshot-testing) to test my new (somewhat asychronous) Wrapped HStack?

I followed this Gist and used this code to create the snapshot test:

    func test_wrappingHStack() {
        let view = ScrollView {
            VStack {
                Text("Title").font(.headline)
                WrappingHStack(models: ["Ninetendo", "XBox", "PlayStation", "PlayStation 2", "PlayStation 3", "PlayStation 4", "Apple", "Google", "Amazon", "Microsoft", "Oracle", "Facebook"]) { str in
                    Text(str)
                }
                Button("Click me") {}
            }
        }
        assertSnapshot(matching: view.toViewController(), as: .image, record: true)
    }

extension SwiftUI.View {
    func toViewController() -> UIViewController {
        let viewController = UIHostingController(rootView: self)
        viewController.view.frame = UIScreen.main.bounds
        return viewController
    }
}

The screenshot I get from the test is: blank image

skywalkerdude
  • 117
  • 1
  • 8
  • Welcome to SO - Please take the [tour](https://stackoverflow.com/tour) and read [How to Ask](https://stackoverflow.com/help/how-to-ask) to improve, edit and format your questions. All the code should be included in the question. Without a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) it is impossible to help you troubleshoot. – lorem ipsum Mar 05 '22 at 13:25

0 Answers0