[Shallow]Call update() automatically through get querys #1499
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.