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

callOnTapGesture not working when in async #334

Open
nh7a opened this issue Sep 18, 2024 · 0 comments
Open

callOnTapGesture not working when in async #334

nh7a opened this issue Sep 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@nh7a
Copy link
Contributor

nh7a commented Sep 18, 2024

callOnTapGesture() does not work when the view is presented with host() async.
Tested with Xcode 16.0 with Swift 6.0 mode.

struct TapGestureView: View {
    @State var flag = false
    let inspection = Inspection<Self>()

    var body: some View {
        Text("flag = \(flag)")
            .onTapGesture { self.flag.toggle() }
            .onReceive(inspection.notice) { self.inspection.visit(self, $0) }
    }
}

final class TapGestureViewTests: XCTestCase {

    @MainActor func test_regular_host() throws {
        let sut = TapGestureView()
        let exp = sut.inspection.inspect { view in
            XCTAssertEqual(try view.anyView().text().string(), "flag = false")
            try view.anyView().text().callOnTapGesture()
            XCTAssertEqual(try view.anyView().text().string(), "flag = true")  // 🆗
        }
        ViewHosting.host(view: sut)
        wait(for: [exp], timeout: 1)
    }

    @MainActor func test_async_host() async throws {
        let sut = TapGestureView()
        try await ViewHosting.host(sut) {
            let view = try $0.inspect()
            XCTAssertEqual(try view.anyView().text().string(), "flag = false")
            try view.anyView().text().callOnTapGesture()
            XCTAssertEqual(try view.anyView().text().string(), "flag = true")  // 💥
        }
    }
}
@nalexn nalexn added the bug Something isn't working label Nov 24, 2024
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