-
Notifications
You must be signed in to change notification settings - Fork 860
test: React 18 act() adjustments #6943
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
test: React 18 act() adjustments #6943
Conversation
c72d471 to
fcc0e7e
Compare
| "@svgr/core": "8.0.0", | ||
| "@svgr/plugin-jsx": "^8.0.1", | ||
| "@svgr/plugin-svgo": "^8.0.1", | ||
| "@testing-library/dom": "^8.12.0", |
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.
@testing-library/dom is unused at this point as this PR switches to using fireEvent imported from @testing-library/react (and automatically wrapped in act() so we don't need to do that manually)
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.
Nice - was that a recent change in @testing-library/react? Or did I just add a library I didn't need to when I was originally setting up RTL? 😅
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 believe it existed for quite some time now, but it was never well documented and people get confused all the time!
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.
Doh! Thanks a million for the cleanup in that case! 💯
|
|
||
| component.setState({ isListOpen: true }); | ||
| act(() => { | ||
| component.setState({ isListOpen: true }); |
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.
React 17 act() can only return void or Promise so all one-liners like this one need to be inserted in a block
1Copenut
left a comment
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.
👍 LGTM!
… latter exports are wrapped in act()
…tAdvanceTimersByTime utility function
fcc0e7e to
d119980
Compare
|
FYI I switched to importing |
Nice, that totally makes sense! |
cee-chen
left a comment
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.
Thanks for taking a little longer to yarn about code abstraction and answer my various questions Tomasz! Changes look great!
* test: replace @testing-library/dom with @testing-library/react as the latter exports are wrapped in act() * test: wrap function calls with act() that need it * test: use act() wrapper for jest.advanceTimersByTime calls and add actAdvanceTimersByTime utility function * test: wait for element to be rendered before taking a snapshot to fix act() warning
* test: replace @testing-library/dom with @testing-library/react as the latter exports are wrapped in act() * test: wrap function calls with act() that need it * test: use act() wrapper for jest.advanceTimersByTime calls and add actAdvanceTimersByTime utility function * test: wait for element to be rendered before taking a snapshot to fix act() warning
* test: replace @testing-library/dom with @testing-library/react as the latter exports are wrapped in act() * test: wrap function calls with act() that need it * test: use act() wrapper for jest.advanceTimersByTime calls and add actAdvanceTimersByTime utility function * test: wait for element to be rendered before taking a snapshot to fix act() warning
* test: replace @testing-library/dom with @testing-library/react as the latter exports are wrapped in act() * test: wrap function calls with act() that need it * test: use act() wrapper for jest.advanceTimersByTime calls and add actAdvanceTimersByTime utility function * test: wait for element to be rendered before taking a snapshot to fix act() warning
Summary
This PR adds act() wrappers in a few places to ensure correct execution when running on React 18 and earlier versions.
QA
yarnto install dependenciesREACT_VERSION=17 yarn test-unitand ensure there'sRunning tests on React v17printed out and there are no failing testsyarn test-unitand confirmRunning tests on React v18is printed out and there are some failing tests, but none are caused byact()warnings.