Open
Description
1. Don't wrap fireEvent
with act
);
const button = getByRole('button');
+ fireEvent.keyDown(document.body, { key: 'TAB' });
act(() => {
- fireEvent.keyDown(document.body, { key: 'TAB' });
button.focus();
});
2. act
should be awaited
As per mui/material-ui#41061 (comment)
From the docs:
We recommend using
act
withawait
and anasync
function. Although the sync version works in many cases, it doesn’t work in all cases and due to the way React schedules updates internally, it’s difficult to predict when you can use the sync version.
We will deprecate and remove the sync version in the future.
This is causing hard to debug issues. We should make our tests more robust and remove all sync usage of act
.
const button = getByRole('button');
fireEvent.keyDown(document.body, { key: 'TAB' });
- act(() => {
+ await act(async () => {
button.focus();
});
Also investigate if we can leverage eslint to discourage sync usage of act
, see testing-library/eslint-plugin-testing-library#915
Search keywords: