[Shallow]Call update() automatically through get querys#1499
Merged
ljharb merged 1 commit intoenzymejs:masterfrom Jun 26, 2018
Merged
[Shallow]Call update() automatically through get querys#1499ljharb merged 1 commit intoenzymejs:masterfrom
ljharb merged 1 commit intoenzymejs:masterfrom
Conversation
813daab to
013e85e
Compare
4 tasks
ljharb
requested changes
Feb 23, 2018
| return this[ROOT]; | ||
| } | ||
|
|
||
| getRootNodeInternal() { |
Member
There was a problem hiding this comment.
we tried pretty hard in v3 to minimize the public API. Can this be a normal function instead of a class method?
ljharb
approved these changes
Jun 26, 2018
Contributor
Author
|
Thanks! |
This was referenced Aug 8, 2018
This was referenced Oct 1, 2018
Merged
This file contains hidden or 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
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
childfrom the updated RootShallowWrapper with the same condition.But enzyme has to care about a case that can't get
childdue 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 separatedRootShallowWrapperandChildShallowWrapper.