-
Notifications
You must be signed in to change notification settings - Fork 158
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
How to verify that a view injects an environmentObject to one of its subviews #149
Comments
Hey @pobengtsson , I see where the problem is. That being said, when you request I consider this a bug in the library, as the env object technically can be injected in the view before returning from I'll work on a fix for the coming next version (or you can try fixing it if you want). Thanks for the report! |
As a separate note, there is no need to create expectation as the func testTT() throws {
var sut = ParentView()
let expectation = sut.on(\.didAppear) { view in
_ = try view.find(ChildView.self).actualView().anObject
}
ViewHosting.host(view: sut.environmentObject(TheObject()))
wait(for: [expectation], timeout: 1)
} |
Thanks for the instant feedback. |
(A solution proposal ready become a PR for this issue, if you would be willing to consider it)
I have a custom view that uses custom child views. The child views depends on an @EnvironmentObject.
I want to test that the parent view injects the environment object as expected, but when I try:
I get fatal error that anObject is not set on the child. As I understand other issues concerning EnvironmentObject (#88, #32, #62) this is not (yet?) supported.
So, then I thought, well maybe I can at least check that the parent view has the modifier set with the type of object that I expect, but I could not find any support for that. I found support for getting the modifier-injected-value when it was writable-key.
After some debugging/code broswing/reading, I found that there the code was quite prepared for what I wwas looking for and there was only a few funcs to be added to make it work. And, low and behold, it seems to work.
Would you be interesting in a PR (including tests) for this?
Or, would you recommend another way of verifying the behaviour concerning environmentObject?
The text was updated successfully, but these errors were encountered: