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

Using enviromentObjects prevents ViewInspector from seeing views #227

Open
AnthonyTTaylor opened this issue Feb 3, 2023 · 2 comments
Open
Labels
more info needed The progress is halted due to insufficient information

Comments

@AnthonyTTaylor
Copy link

ViewInspector 0.9.1
Xcode 14.2
Swift 5.2

Using ViewInspector version 0.9.1 (tested on 0.9.5 and still same issue) in my tests, I would be able to reference views with the code below.

        let view = MyGarageAccountSettingsDeleteView()
        let navigationView = try view.inspect()
        let scrollView = try navigationView.scrollView(0)

However, once I add an enviromentObject into the view, it does not allow me to reference the scrollView. I need to change to search the entire view for type scollView.

I am new to ViewInspector, however unless I am missing something I think this is a true issue with regards to enviromentObjects.

        let view = MyGarageAccountSettingsDeleteView().environmentObject(myGarageSheet)
        let navigationView = try view.inspect()
        let scrollView = try navigationView.findAll(ViewType.ScrollView.self).first
@nalexn
Copy link
Owner

nalexn commented Jul 13, 2023

Hey, could you share a minimal code of MyGarageAccountSettingsDeleteView view that reproduces the issue? I've tried with the following view and test works fine:

struct MyGarageAccountSettingsDeleteView: View {
    
    @EnvironmentObject var obj: TestEnvObject

    var body: some View {
        NavigationView {
            ScrollView {
                Text(obj.value)
            }
        }
    }
}

class TestEnvObject: ObservableObject {
    @Published var value = "env"
}

func testEnvObject() throws {
    let view = MyGarageAccountSettingsDeleteView().environmentObject(TestEnvObject())
    let navigationView = try view.inspect().navigationView()
    XCTAssertNoThrow(try navigationView.scrollView(0))
    XCTAssertEqual(try view.inspect().findAll(ViewType.ScrollView.self).count, 1)
}

@nalexn nalexn added help wanted Extra attention is needed more info needed The progress is halted due to insufficient information and removed help wanted Extra attention is needed labels Jul 13, 2023
@virgilius-santos
Copy link

the error occurs for me if you don't pass the environmentObject

struct MyGarageAccountSettingsDeleteView: View {
        
        @EnvironmentObject var obj: TestEnvObject

        var body: some View {
            NavigationView {
                ScrollView {
                    EmptyView()
                }
            }
        }
    }

    class TestEnvObject: ObservableObject {
        @Published var value = "env"
    }

    func testEnvObject() throws {
        let view = MyGarageAccountSettingsDeleteView()
        let navigationView = try view.inspect().navigationView()
    }

error

failed: caught error: "navigationView() found MyGarageAccountSettingsDeleteView instead of NavigationView"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed The progress is halted due to insufficient information
Projects
None yet
Development

No branches or pull requests

3 participants