nalexn / ViewInspector

Runtime introspection and unit testing of SwiftUI views
MIT License
2.21k stars 155 forks source link

Any way to test Shape fill color? #357

Open jonreid opened 1 day ago

jonreid commented 1 day ago

The fill color in this view is currently hardcoded to blue. I'd like to vary the color. Is there a way to test the fill Color?

private struct CheckButton: View {
    var body: some View {
        Button(action: {
        }, label: {
            RoundedRectangle(cornerRadius: 10)
                .fill(Color.blue)
                .frame(width: 100, height: 200)
                .overlay(
                    Text("Check")
                        .foregroundColor(.white)
                        .font(.title)
                )
        })
        .tag("checkButton")
    }
}
nalexn commented 1 day ago
let color = try sut.inspect().<path_to_rounded_rectangle>.shape().fillShapeStyle(Color.self)
XCTAssertEqual(color, .blue)