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

Element inspection not working #346

Open
rishipandey opened this issue Oct 18, 2024 · 0 comments
Open

Element inspection not working #346

rishipandey opened this issue Oct 18, 2024 · 0 comments

Comments

@rishipandey
Copy link

rishipandey commented Oct 18, 2024

have created a sample view with a List in XCode 16:

struct TestListView: View {
    let items = ["Item 1", "Item 2", "Item 3"]

    var body: some View {
        List {
            ForEach(items, id: \.self) { item in
                Text(item)
            }
        }
    }
}

Now, I have created inspection tests:

final class TestListViewTests: XCTestCase {

    func testListItemCount() throws {
        let view = TestListView()

        let list = try view.inspect().list()
        let forEach = try list.forEach(0)
        
        XCTAssertEqual(forEach.count, 3)
    }

    func testListItemContents() throws {
        let view = TestListView()

        let list = try view.inspect().list()
        let forEach = try list.forEach(0)

        XCTAssertEqual(try forEach[0].text().string(), "Item 1")
        XCTAssertEqual(try forEach[1].text().string(), "Item 2")
        XCTAssertEqual(try forEach[2].text().string(), "Item 3")
    }
}

However, these tests throw the following error:
failed: caught error: "list() found TestApp_SwiftUI.TestListView instead of List"

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

1 participant