-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[core] Update tooling to run with React 18 #4155
Conversation
These are the results for the performance tests:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
packages/grid/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid-pro/src/tests/rows.DataGridPro.test.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid/src/hooks/utils/useGridApiEventHandler.test.tsx
Show resolved
Hide resolved
packages/grid/x-data-grid/src/tests/pagination.DataGrid.test.tsx
Outdated
Show resolved
Hide resolved
packages/x-date-pickers-pro/src/MobileDateRangePicker/MobileDateRangePicker.test.tsx
Show resolved
Hide resolved
clock.tick(500); | ||
fireEvent.keyDown(input, { key: 'Enter' }); | ||
await act(() => Promise.resolve()); | ||
|
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 don't understand why some lines bellow you use
await act(() => clock.tick(500))
and here you can simply keep
clock.tick(500)
About await act(() => Promise.resolve());
would it make sense to create an helper
waitForTimeoutExecution = async () => act(() => Promise.resolve());
such that when reading the code await waitForTimeoutExecution()
bring more information
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.
Which line you're referring to? Note that the tests for the old editing API have some useless code, like waitFor
being used with fake timers = no difference.
About the helper, we could add it but only waiting for the promise is not enough for "timeout completion". If the clock is fake, the time has to be manually advanced too.
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.
Was looking at lin 240 await act(async () => clock.tick(500));
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 reviewed this entire file removing useless code. Now most tests use only clock.tick(500)
or clock.tick(500)
+ await act(() => Promise.resolve());
.
This comment was marked as outdated.
This comment was marked as outdated.
|
||
await new Promise((resolve) => nativeSetTimeout(resolve)); // Wait for promise | ||
await Promise.resolve(); // Wait for promise |
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.
Should this be also wrapped in an act
? There is one more case couple of lines below.
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 removed the second one. It was doing nothing.
This PR updates the React version in all
package.json
to v18.x. As consequence, I had to update a bunch of tests to work in this version without warnings. I noticed 3 types of change it caused:API calls now need to be wrapped in
act
to avoid warnings likeBasically we only need to do:
But it can get complex if the update happens inside a Promise so https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning may help.
When doing
expect().toErrorDev([...])
we need to duplicate the first message.Now the errors generated by StrictMode are also sent to
console.error
. In React 17, the 2nd render made by StrictMode replacedconsole.error
with a no-op version.expect(() => { render( <ErrorBoundary> <GridOverlay /> </ErrorBoundary>, ); }).toErrorDev([ 'MUI: useGridRootProps should only be used inside the DataGrid, DataGridPro or DataGridPremium component.', + 'MUI: useGridRootProps should only be used inside the DataGrid, DataGridPro or DataGridPremium component.', 'The above error occurred in the <ForwardRef(GridOverlay)> component', ]);
When asserting that something was called X times, and one of the times was caused by an effect, we need to account for StrictEffects
Each effect runs twice so the expectation has to consider that.