-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Removing or documenting the need for Shallow Renderer's .update() #360
Comments
One thing we could try to do that would help with some of these situations is make sure every time the component internally calls |
wrapping/injecting around Example test for each: master...jwbay:update The impure render case currently in the example for |
I need to think about this some more, I wonder if there's some reason why the shallow renderer from react (as for impure render methods there's nothing we can do, those will always have to be manual) |
It needs to call This way, the rendered output will always be up to date regardless of what goes on behind the scenes. |
…tput is always fresh. removes need for .update, fixes enzymejs#360
…tput is always fresh. removes need for .update, fixes enzymejs#360
…tput is always fresh. removes need for .update, fixes enzymejs#360
I had a related issue in #517 and would like to get behind OP on this. As a relatively new user to both React and Enzyme, it feels very natural to me that calling |
The problem
When testing interactions with shallow rendered components, what interactions do and don't need
.update()
after them can feel inconsistent. If the component's rendered output doesn't match what you think it should after performing some action, you can end up littering tests with.update()
hoping to get lucky.It wasn't until I peeked at the source and saw the
.update()
call in.simulate()
that everything made sense. Even knowing that unless I'm using a few "blessed" methods I'll need to call.update()
myself it's still going to trip me up at times.The solution
Is it feasible to wrap rendering such that whenever a component is rendered
.update()
is called afterward automagically? Via wrapping .prototype.render, I suppose, though hopefully there's a more clever solution or hook somewhere.Or at least, an update to
.update()
's docs to be clear about the cases where it's called for you could help greatly. From what I saw, this is just.simulate
and.setProps/State/Context
?The text was updated successfully, but these errors were encountered: