Open oliviertassinari opened 4 months ago
On point 2. I wonder how true "This is causing hard to debug issues." is. They seem to report errors when an await is missing: https://github.com/facebook/react/blob/1460d67c5b9a0d4498b4d22e1a5a6c0ccac85fdd/packages/react/src/ReactAct.js#L122
Edit: looks like it's not true, it's needed: https://github.com/testing-library/react-testing-library/issues/1061#issuecomment-1140112314.
From https://github.com/mui/material-ui/pull/44028#pullrequestreview-2352318687, potential eslint rule to help use with 2:
'no-restricted-syntax': [
'error',
{
selector: "CallExpression[callee.name='act'] > ArrowFunctionExpression:not([async=true])",
message: 'Synchronous form of `act` is not allowed. Use `await act(async () => {...})` instead.',
},
{
selector: "CallExpression[callee.name='act']:not(AwaitExpression > CallExpression[callee.name='act'])",
message: '`act` must be awaited. Use `await act(async () => {...})` instead.',
},
],
We could plan some time to do a full sweep of the codebase, in my limited experience the sync version doesn't always work as expected. I wouldn't be surprised if https://github.com/mui/mui-x/pull/14668 magically starts working if we remove all sync act
calls.
1. Don't wrap
fireEvent
withact
Example: https://github.com/mui/material-ui/blob/0bddcac5beeb535c36fa2055082cc8324e59c282/packages/mui-material/src/Button/Button.test.js#L612-L615
2.
act
should be awaitedAs per https://github.com/mui/material-ui/pull/41061#discussion_r1631251653
From the docs:
This is causing hard to debug issues. We should make our tests more robust and remove all sync usage of
act
.Also investigate if we can leverage eslint to discourage sync usage of
act
, see https://github.com/testing-library/eslint-plugin-testing-library/issues/915Search keywords: