[test][material-ui] Remove unnecessary async act calls#42942
[test][material-ui] Remove unnecessary async act calls#42942aarongarciah merged 4 commits intomui:nextfrom
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.
Per React docs, act is meant to be awaited 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.
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 |
|
@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 unnecessaryactcalls wrapping Testing Library helpers likefireEvent, because these helpers already callactfor us.This PR removes unnecessary
actcalls from several test suites, making the code follow the "rules" of Testing Library and thus removing the ESLint errors. Also addsawait/asynctoactcalls in the modified files as recommended in the React docs.Context: #41061 (comment)
(Thanks @Janpot for the tip!)