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

Find causes @EnvironmentObject crashes #87

Closed
Tyler-Keith-Thompson opened this issue Mar 1, 2021 · 1 comment
Closed

Find causes @EnvironmentObject crashes #87

Tyler-Keith-Thompson opened this issue Mar 1, 2021 · 1 comment

Comments

@Tyler-Keith-Thompson
Copy link
Contributor

If you're using the find functionality so search for something in the view hierarchy after something with an environment object thar be crashes. I tried for about 3 hours to dig into this and understand the different between calling view(Type.self) (which works) vs find(Type.self) but it's honestly gonna take longer to understand all of the inner workings of the library. Here is a test that reproduces my issue:

// In your view search tests, where you define views:
final class ModelData: ObservableObject {
    var stringProperty = "Model"
}
struct EnvironmentView: View, Inspectable {
    @EnvironmentObject var data: ModelData
    var body: some View {
        Text(data.stringProperty)
   }
}

// Thing that crashes but shouldn't
func testFindPastViewWithEnviornmentObject() throws {
    struct Embedded: View, Inspectable {
        var body: some View {
            Test.EnvironmentView()
            Text("")
        }
    }
    let view = try Embedded().inspect()
    XCTAssertNoThrow(try view.find(ViewType.Text.self))
}
@nalexn
Copy link
Owner

nalexn commented Mar 13, 2021

This just got fixed as of v0.7.0

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

2 participants