Widget extension, SwiftUI, Snapshot testing

585 views Asked by At

I'm working on widget extension for one of our applications. Everything goes smooth, I can add and display the widget and I also have unit tests for our view model and etc. Next is I'm trying to do a snapshot testing for widget UI and using Quick and Nimble framework. I read some articles about how to do it for SwiftUI and currently I'm doing like suggested.

  func testExample() throws {
        let contentView = ContentView() // conteView is containing some text + images.
        let view = contentView(width: 155, height: 155, alignment: .center)
        let controller = UIHostingController(rootView: view)
        controller.view.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
        expect(controller.view) == recordSnapshot()
    }

The result is that Im getting a snapshot for blank view.Therefore, I'm putting breakpoints for debugging at

let contentView = ContentView() // conteView is containing some text + images.

It turns out that it does not step through ui layout in ContentView()

I notice that we are able to do snapshot testing for SwiftUI. However, I'm not sure if we are able to do so for widget extension which also used SwiftUI.

Any thoughts on it and all answers are appreciate.

Thanks

0

There are 0 answers