Skip to content
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

Bug: unexpected Warning: ReactDOMTestUtils.act is deprecated in favor of React.act. #29000

Closed
salier1 opened this issue May 6, 2024 · 14 comments

Comments

@salier1
Copy link

salier1 commented May 6, 2024

I didn't use act in react-dom/test-utils but I got the following warning :
Warning: ReactDOMTestUtils.act is deprecated in favor of React.act. Import act from react instead of react-dom/test-utils. See https://react.dev/warnings/react-dom-test-utils for more info.

React version:18.3.1

Steps To Reproduce

1.run npx create-react-app test --template typescript
2.run cd test
3.run npm run test
4.press a

image
@salier1 salier1 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label May 6, 2024
@eps1lon
Copy link
Collaborator

eps1lon commented May 6, 2024

You should bump the installed version of @testing-library/react to at least 15.0.6 to get rid of the deprecation warning.

@eps1lon eps1lon closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
@eps1lon eps1lon added Resolution: Support Redirect and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels May 6, 2024
@Jacobmrose
Copy link

npm install --save-dev @testing-library/react resolved this issue for me.

@ShanComcast
Copy link

My issue also got resolved. Thanks a lot @Jacobmrose.

@bluejs
Copy link

bluejs commented May 31, 2024

you made my day, thanks @Jacobmrose

@sorinpav
Copy link

sorinpav commented May 31, 2024

@eps1lon We still see this issue.

The version of @testing-library/react: ^15.0.7
I also did an npm install --save-dev @testing-library/react and it still didn't resolve the issue for us, unfortunately. Can this please be reopened?

@rickhanlonii
Copy link
Member

Unfortunately, there's nothing we can do here. If something is using act from test-utils you need to find the callsite and either fix it, upgrade the library that's doing it, or file an issue for the library to fix it.

wu-jeffrey added a commit to wu-jeffrey/tour-to that referenced this issue May 31, 2024
- kept getting: `Warning: ReactDOMTestUtils.act is deprecated in favor of React.act`
- found a fix that recommended version bumping: facebook/react#29000
- no issues after build & clean so hopefully this doesn't cause any transitive dep issues
@eps1lon
Copy link
Collaborator

eps1lon commented Jun 1, 2024

@sorinpav Your testing framework should add a callstack to the console.error which should help you identify where the wrong act is called. @testing-library/react should use React.act iff it is available i.e. react@>=18.3.1 is installed next to @testing-library/react. Either you have react@18.3.0 directly installed or you have multiple versions of React installed. Remember, react@18.3.0 would not be sufficient. It must be 18.3.1 or 19.x.

@sorinpav
Copy link

sorinpav commented Jun 1, 2024

@eps1lon thanks for the reply. There are no instances of act from react-dom/test-utils in our project, and we only import it directly from React, but I can't remember exactly what version of React we're using. I'll have a look. It's the project at work that I'm quoting here. I'll come back with a comment. Thanks!

@sorinpav
Copy link

sorinpav commented Jun 1, 2024

@rickhanlonii understood. Just saw your comment now. (I'm on mobile and it was harder to see)
I'll see what I can do. As mentioned above, we don't call it directly, so it may be only third party modules that are calling into it 🥲..

@sorinpav
Copy link

sorinpav commented Jun 1, 2024

Just checked now, and we are on react / react-dom:^18.3.1, but I think I know what is causing it. We're unfortunately still using the enzyme react 17 adapter. Our test codebase is split in between React Testing Library and Enzyme still (long migration process), and I've just spotted that the enzyme react 17 adapter still uses the old import destination.

Posting this more for others that discover this same issue. For now, I don't think it needs reopening. Thanks guys for the help!

@parksu0219
Copy link

parksu0219 commented Jul 2, 2024

I was getting the same warning message while using @testing-library/react (v14.0.0).

I updated v14.0.0v14.1.2, and it worked for me.

import { act } from '@testing-library/react'

@Navee-n
Copy link

Navee-n commented Jul 18, 2024

Updating worked for me

@homayunmmdy
Copy link

Thanks It's worked

@nditanaka
Copy link

ran into the same issue - thanks @Jacobmrose! running

npm install --save-dev @testing-library/react resolved this issue for me.

fixed it for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests