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

image

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 17 (1 by maintainers)

Commits related to this issue

Most upvoted comments

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

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

In case this helps anyone else:

Bumping @testing-library/react to at least 15.0.6 did 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 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.

ran into the same issue - thanks @Jacobmrose! running

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

fixed it for me