Update test comments with explanations #21857
Merged
+38
−55
Conversation
packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js
Show resolved
Hide resolved
|
Comparing: 87b67d3...02656e8 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
5cc755c
to
bff5fe5
| expect(Scheduler).toFlushAndYieldThrough([ | ||
| 'render: 2', | ||
| 'componentDidUpdate: 2', | ||
| 'componentDidUpdate (before setState): 2', | ||
| 'componentDidUpdate (after setState): 2', | ||
| // This renders because the scheduled update is default, which is sync. |
acdlite
Jul 13, 2021
Member
This isn't right, the "3" update is deferred (deferredUpdates is basically just startTransition, we should remove it)
The reason it appears in this assertion is that toFlushAndYieldThrough will keep rendering until the logs match, and only fails if the expected items are different or if it's unable to yield after the last item.
You should be able to remove the gate condition on line 285. if you wrap the setState({tick: 2}) in startTransition, i.e. this behavior should work in both branches:
// Increment the tick to 2. This will trigger an update inside cDU. Flush
// the first update without flushing the second one.
React.startTransition(() => {
instance.setState({tick: 2});
});
expect(Scheduler).toFlushAndYieldThrough([
'render: 2',
'componentDidUpdate: 2',
'componentDidUpdate (before setState): 2',
'componentDidUpdate (after setState): 2',
]);
expect(ReactNoop).toMatchRenderedOutput(<span prop={2} />);
// Now flush the cDU update.
expect(Scheduler).toFlushAndYield(['render: 3', 'componentDidUpdate: 3']);
expect(ReactNoop).toMatchRenderedOutput(<span prop={3} />);
This isn't right, the "3" update is deferred (deferredUpdates is basically just startTransition, we should remove it)
The reason it appears in this assertion is that toFlushAndYieldThrough will keep rendering until the logs match, and only fails if the expected items are different or if it's unable to yield after the last item.
You should be able to remove the gate condition on line 285. if you wrap the setState({tick: 2}) in startTransition, i.e. this behavior should work in both branches:
// Increment the tick to 2. This will trigger an update inside cDU. Flush
// the first update without flushing the second one.
React.startTransition(() => {
instance.setState({tick: 2});
});
expect(Scheduler).toFlushAndYieldThrough([
'render: 2',
'componentDidUpdate: 2',
'componentDidUpdate (before setState): 2',
'componentDidUpdate (after setState): 2',
]);
expect(ReactNoop).toMatchRenderedOutput(<span prop={2} />);
// Now flush the cDU update.
expect(Scheduler).toFlushAndYield(['render: 3', 'componentDidUpdate: 3']);
expect(ReactNoop).toMatchRenderedOutput(<span prop={3} />);
acdlite
Jul 13, 2021
Member
Could also use toFlushUntilNextPaint instead
Could also use toFlushUntilNextPaint instead
rickhanlonii
Jul 15, 2021
Author
Member
Ah, right nice catch.
Ah, right nice catch.
bff5fe5
to
0396149
0396149
to
02656e8
5579f1d
into
facebook:main
33 of 34 checks passed
33 of 34 checks passed
ci/circleci: yarn_test--r=stable --env=development --persistent
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test--r=www-classic --env=development --variant=false
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test--r=www-classic --env=development --variant=true
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test--r=www-classic --env=production --variant=false
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test--r=www-classic --env=production --variant=true
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test--r=www-modern --env=development --variant=false
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test--r=www-modern --env=development --variant=true
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test--r=www-modern --env=production --variant=false
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test--r=www-modern --env=production --variant=true
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_build---project=devtools -r=experimental
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_build--r=experimental --env=development
Your tests passed on CircleCI!
Details
ci/circleci: yarn_test_build--r=experimental --env=production
Your tests passed on CircleCI!
Details
sthagen
added a commit
to sthagen/react
that referenced
this pull request
Jul 19, 2021
Update test comments with explanations (facebook#21857)
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.
I understand this well enough to explain these now.