-
-
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
[Shallow]Call update() automatically through get querys #1499
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
koba04
force-pushed
the
auto-update
branch
2 times, most recently
from
February 12, 2018 09:17
813daab
to
013e85e
Compare
4 tasks
ljharb
requested changes
Feb 23, 2018
@@ -152,11 +152,17 @@ class ShallowWrapper { | |||
return this[ROOT]; | |||
} | |||
|
|||
getRootNodeInternal() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we tried pretty hard in v3 to minimize the public API. Can this be a normal function instead of a class method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed it.
ljharb
approved these changes
Jun 26, 2018
Thanks! |
This was referenced Aug 8, 2018
This was referenced Oct 1, 2018
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Enzyme v3, I saw many issues about changes that we have to call
update()
afterinstance.setState()
.Actually,
wrapper.update()
doesn't rerender even though the name implies to update something.wrapper.update()
only does to get a latest ReactElementTree from ReactShallowRenderer.I think it would be nice if developers don't care about calling
wrapper.update()
.In this case, enzyme can't handle all cases that need to call
wrapper.update()
.In order to resolve this, this PR adopts a pull-based approach, which calls
wrapper.update()
in getter for internal nodes.So we can get the latest node through the enzyme APIs (
find
,text
, ...).This PR is for ShallowWrapper, but I could apply this to ReactWrapper as well.
But there is a limitation.
This PR doesn't cover that a wrapper isn't RootShallowWrapper.
Covering the case might be difficult because enzyme has to get
child
from the updated RootShallowWrapper with the same condition.But enzyme has to care about a case that can't get
child
due to the update.I think it seems to be good that wrappers that are not RootShallowWrapper treat as immutable.
BTW. ShallowWrapper has the condition(
this[ROOT] === this
) in many methods, I think it becomes clearer if ShallowWrapper can be separatedRootShallowWrapper
andChildShallowWrapper
.