-
Notifications
You must be signed in to change notification settings - Fork 153
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
Feature Request: Allow tests to specify environment #167
Comments
Hey @Tyler-Keith-Thompson , the The way it works is that after we extracted the child as a struct, we patch its internal references to point to the EnvironmentObject inherited from the parent before returning to the user. Apparently, after the state changes for the child, a new struct is created and it needs to be patched again. |
Cool, I'll work on a PR. FWIW my use-case seems to be more complex because distilling it down to a minimally reproducible example has been quite challenging. Regardless, I think this feature will help. |
I'm using |
I believe this is a minimal reproduction of the problem. A view is displayed on a state change which requires access to the environment context. This works fine when running the app, but fails in the test with Hope that helps track down the issue. |
The problem
I've been running into a plethora of
EnvironmentObject
issues. Seemingly, nested views that rely on it have lots of issues finding it after state changes.My specific use-case could be summed up as, I have a view heavily dependent on an environment object, I want ViewInspector to prove that the parent displays that view as a sheet after a state change. Unfortunately, before the state change in the parent, it has the environment objects, but after it keeps telling me the environment objects aren't there. I've also had BAD_ACCESS instructions and other bizarre behavior when ViewInspector tries to handle the environment itself.
While this specific problem could be tracked down this smacks to me of ViewInspector constantly having to track down and attempt to duplicate very complex environment scenarios.
Potential Solution
Let consumers of the library specify the environment to ViewInspector. I believe this has several advantages:
ViewHosting.view(someView.environmentObject(injected))
this allows more explicit control with arrange-act-assert based tests. (Given my environment is , When my view , Then )Inspection
class to be injected into prod code. I think this is true because I believe nested views would largely be functional, therefore you could create a view wrapper that did much the same thing asInspection
I'll stop there because it's a lot to read. If there's interest, I'm happy to create a discussion and talk through some of my API design ideas. I am also willing to do the grunt work and submit a PR, assuming others believe this to be a worthwhile approach.
The text was updated successfully, but these errors were encountered: