-
-
Notifications
You must be signed in to change notification settings - Fork 32.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
[test][material-ui] Remove unnecessary async act calls #42942
[test][material-ui] Remove unnecessary async act calls #42942
Conversation
Netlify deploy previewhttps://deploy-preview-42942--material-ui.netlify.app/ Bundle size report |
@romgrk let me know if you're ok with these changes. |
45f644e
to
1e22be8
Compare
expect(onKeyUp.callCount).to.equal(1); | ||
|
||
act(() => { | ||
await act(async () => { |
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.
Per React docs, act
is meant to be await
ed and the callback passed to it to be async
:
We recommend using act with await and an async 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.
Source: https://react.dev/reference/react/act#await-act-async-actfn
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.
We should probably create an ESLint rule for this in the future if there's no "official" one.
LGTM, as long as the tests pass I don't really have an opinion. But IIUC all the comments, the |
The fireEvent calls don't seem to be async though, they must rely on the sync behavior of |
I left a question in the Testing Library Discord to see if the plan is to update I wonder if we should wait for |
This is the And this is where it's used in |
@eps1lon is working on |
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.
Looks great
@romgrk @Janpot this is the response from @eps1lon after being questioned about if we should do
We can forget about this for now. I'd recommend using |
We're working on adopting
eslint-plugin-testing-library
(issue) and it errors when it finds unnecessaryact
calls wrapping Testing Library helpers likefireEvent
, because these helpers already callact
for us.This PR removes unnecessary
act
calls from several test suites, making the code follow the "rules" of Testing Library and thus removing the ESLint errors. Also addsawait
/async
toact
calls in the modified files as recommended in the React docs.Context: #41061 (comment)
(Thanks @Janpot for the tip!)