react: Bug: unexpected Warning: `ReactDOMTestUtils.act` is deprecated in favor of `React.act`.
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 17 (1 by maintainers)
Commits related to this issue
- [M1][test] fix deprecation warning for unit tests - kept getting: `Warning: ReactDOMTestUtils.act is deprecated in favor of React.act` - found a fix that recommended version bumping: https://github.c... — committed to wu-jeffrey/tour-to by wu-jeffrey 2 years ago
- Update @testing-library/react to get rid of the deprecation warning https://github.com/facebook/react/issues/29000 — committed to uraitakahito/hello-create-react-app by uraitakahito 2 years ago
npm install --save-dev @testing-library/react resolved this issue for me.
You should bump the installed version of
@testing-library/reactto at least15.0.6to get rid of the deprecation warning.In case this helps anyone else:
Bumping
@testing-library/reactto at least15.0.6did not clear the warning for me.I did that and then I followed the React Hooks Testing Library Migration guide and that solved the problem.
It is happening for me in v16.0.1 - the latest release.
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!
@sorinpav Your testing framework should add a callstack to the console.error which should help you identify where the wrong
actis called.@testing-library/reactshould useReact.actiff it is available i.e.react@>=18.3.1is installed next to@testing-library/react. Either you havereact@18.3.0directly installed or you have multiple versions of React installed. Remember,react@18.3.0would not be sufficient. It must be18.3.1or19.x.ran into the same issue - thanks @Jacobmrose! running
fixed it for me