L3n95
L3n95

Reputation: 1615

SwiftUI: Assert that sheet is visible

I have a view in which a sheet gets visible at some point.

var body: some View {
    VStack {
        Text("Test")
        Text("Test")
    }.sheet(isPresented: $isPresented, content: {
        MySheet(isPresented: $isPresented)
    })
}

The sheet looks like this:

var body: some View {
    GeometryReader { metrics in
        VStack (spacing:0) {
            ZStack {
                Color(UIColor.lightGray)
                Text("header")
            }.frame(width: metrics.size.width, height: metrics.size.height * 0.15)
            ZStack {
                Color(UIColor.darkGray)
                Text("text")
            }.frame(width: metrics.size.width, height: metrics.size.height * 0.85)
        }
    }
}

I tried to test that the sheet is visible with

XCTAssertTrue(app.textFields["header"].exists)

But that does not work. How can I test if the sheet is visible?

Upvotes: 2

Views: 825

Answers (1)

Asperi
Asperi

Reputation: 257523

For Text you need to use staticTexts container (tested with Xcode 12.1 / iOS 14.1). Assuming of course that your test correctly wait till sheet is opened.

XCTAssertTrue(app.staticTexts["header"].exists)

Upvotes: 2

Related Questions