How to access, and set value of, @Environment(\.editMode) for a view in a test? #257
Replies: 2 comments 2 replies
-
Hey, I'm afraid |
Beta Was this translation helpful? Give feedback.
2 replies
-
Closing. The main discussion is in #131 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
On iOS, I have a view accessing SwiftUI’s built-in
editMode
environment variable. I want to test based on different states (whereself.editMode.wrappedValue == .active
, and whereself.editMode.wrappedValue == .inactive
).Assuming there is a way to properly access the editMode environment variable using ViewInspector, how can I change the value of that variable so I can test how my view responds to different states?
Throws an error (at the line marked with 🛑):
failed - MyView does not have 'environment(Optional<Binding<EditMode>>)' modifier
I then tried to provide the editMode:
Triggers a purple error in
MyView
wherebody
is trying to accessself.editMode
:🟪
Accessing Environment<Optional<Binding<EditMode>>>'s value outside of being installed on a View. This will always read the default value and will not update.
Beta Was this translation helpful? Give feedback.
All reactions