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

Switching selectedTab does not seem to work #164

Closed
haemi opened this issue Mar 11, 2022 · 1 comment
Closed

Switching selectedTab does not seem to work #164

haemi opened this issue Mar 11, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@haemi
Copy link

haemi commented Mar 11, 2022

With the following view

public struct ContentView: View {
    let inspection = Inspection<Self>()
    @State var selectedTab = 1

    public var body: some View {
        TabView(selection: $selectedTab) {
            Button(action: {
                selectedTab = 2
            }, label: {
                Text("one")
            })
            .tabItem {
                VStack {
                    Text("Tab 1")
                }
            }
            .id("myId")
            .tag(1)

            Text("two")
                .tabItem {
                    VStack {
                        Text("Tab 2")
                    }
                }
                .tag(2)
        }
        .onReceive(inspection.notice) { self.inspection.visit(self, $0) }
    }
}

and this test

func myTest() throws {
        let sut = ContentView()
        let exp = sut.inspection.inspect { view in
            XCTAssertEqual(try view.actualView().selectedTab, 1)
            XCTAssertNoThrow(try view.find(text: "one"))
            try view.find(viewWithId: "myId").button().tap()
            XCTAssertEqual(try view.actualView().selectedTab, 2)
        }

        let exp2 = sut.inspection.inspect(after: 2) { view in
            XCTAssertEqual(try view.actualView().selectedTab, 2)
            XCTAssertThrowsError(try view.find(text: "one")) // <==== XCTAssertThrowsError failed: did not throw an error
            XCTAssertNoThrow(try view.find(text: "two"))
        }
        ViewHosting.host(view: sut)
        wait(for: [exp, exp2], timeout: 2)
}

I get the error in the marked line; it seems as if the tab is not switched, or at least ViewInspector does not see the change. Or am I doing something wrong here?

@nalexn nalexn added the help wanted Extra attention is needed label Sep 10, 2022
@nalexn nalexn added the bug Something isn't working label Jan 8, 2023
@nalexn nalexn added pending release A fixed issue that'll be released in an upcoming update and removed help wanted Extra attention is needed labels Jan 14, 2023
@nalexn
Copy link
Owner

nalexn commented Jan 14, 2023

Fixed released with v0.9.4

@nalexn nalexn closed this as completed Jan 14, 2023
@nalexn nalexn removed the pending release A fixed issue that'll be released in an upcoming update label Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants