# Fix "Warning: ReactDOMTestUtils.act is deprecated in favor of React.act" in React Testing Library Tests

Yes. An agent traces the warning to an old @testing-library/react on React 18.3, upgrades the library and its dom peer, reruns the tests clean and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/fix-reactdomtestutils-act-is-deprecated-warning/testing-library/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads the test setup before changing anything. In a Create React App project like mpagels/react-and-morty, a Rick and Morty exercise app, `package.json` asks for `"react": "^18.0.0"`, `"@testing-library/react": "^12.1.4"`, `"@testing-library/jest-dom": "^5.16.3"`, `"@testing-library/user-event": "^13.5.0"` and `"react-scripts": "5.0.0"`, with `"test": "react-scripts test"`. The lockfile pins `react` at 18.0.0 and `@testing-library/react` at 12.1.4, and the one test, `src/App.test.js`, renders `<App />` and asserts the "learn react" link is in the document.

Then it runs the suite twice. With the lockfile as committed, `CI=true npx react-scripts test --watchAll=false` passes and prints one `console.error`, `Warning: ReactDOM.render is no longer supported in React 18`, because Testing Library 12 still mounts through the legacy root. After `npm install react@18 react-dom@18`, which moves both to 18.3.1, the same single test passes and prints three: `Warning: ReactDOMTestUtils.act is deprecated in favor of React.act. Import act from react instead of react-dom/test-utils`, the `ReactDOM.render` line again, and `Warning: unmountComponentAtNode is deprecated and will be removed in the next major release`. All three point at `node_modules/@testing-library/react/dist/pure.js`, not at the app, which is how the agent knows the library and not the test is the subject.

The fix is the library release that uses `React.act` and `createRoot`: `@testing-library/react@16` (16.3.3 today), which also makes `@testing-library/dom` a peer dependency the project must install itself, so the agent adds `@testing-library/dom@10` (10.4.2), and moves `@testing-library/jest-dom` to 6 in the same step. With React still at 18.3.1 the test passes and prints no `console.error` at all. `@testing-library/user-event` stays at 13, since 14 changes its API and nothing in this warning requires it.

It also checks what did not need to change. The test file itself is untouched: `render` and `screen` from `@testing-library/react` keep the same import and the same calls across 12 and 16, and `src/setupTests.js` still imports `@testing-library/jest-dom`. The description says so, with the warning's stack trace quoted, so a reviewer can see the deprecation came from the library's `act` import and not from any test in the repository.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "The test suite prints `Warning: ReactDOMTestUtils.act is deprecated in favor of React.act`. Read package.json and the lockfile and list the installed versions of react, react-dom, @testing-library/react, @testing-library/dom, @testing-library/jest-dom and @testing-library/user-event. Run the test suite and quote every console.error with the file in node_modules it comes from. If the warnings come from @testing-library/react, upgrade it to the current release along with the @testing-library/dom peer it now requires, keep every test file unchanged, and run the suite again to show the same tests pass with no console.error. Do not change user-event unless a test requires it. Open a pull request that quotes both runs.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request touching `package.json` and `package-lock.json` only: `@testing-library/react` moved to 16, `@testing-library/dom` added as a dependency at 10, `@testing-library/jest-dom` moved to 6. The description quotes the three warnings from the React 18.3 run with their `pure.js` stack frames, then the clean run on 16, with the test count unchanged at one passing.

A reviewer checks that no file under `src/` is in the diff, that `@testing-library/dom` is listed rather than left to hoisting, and that the clean run really has no `console.error` rather than a silenced one. The run's record holds both suite runs in full, so the warning text and its disappearance can be opened rather than taken on trust.

## Run it on every pull request labelled react-upgrade

This warning arrives with the pull request that moves React to 18.3, since that release added the deprecation. Add an automation to the repository's Project with a `github` trigger on `pull_request.labeled`, its `labels` filter set to `react-upgrade`, and this prompt. When a maintainer labels the React bump, the run starts with the pull request event placed after the prompt, runs the suite on that branch and opens its own pull request with the Testing Library upgrade, which you merge together with the bump.

The trigger fires only for labels applied by an owner, member or collaborator, never for pull requests from forks, and the automation's own `max_runs_per_hour` caps how often it can start.

## Why run it on Rush?

A deprecation printed from inside `node_modules` tempts people to patch the test, which is the wrong file. The agent runs the suite in its own sandbox and reads the stack frames, so the pull request names the library release that imports `act` from the right place, and every run with its full output stays in the record.

The peer dependency is the part a laptop upgrade misses: Testing Library 16 no longer installs `@testing-library/dom` for you, and a project that forgets it fails on the next clean install. Because the agent does the install from scratch in a clean clone, that requirement shows up in the run and lands in the same pull request.

## Frequently asked questions

### Why does the warning appear only after moving to React 18.3?

React 18.3 added deprecation warnings for APIs React 19 removes, including `ReactDOMTestUtils.act`, `ReactDOM.render` and `unmountComponentAtNode`. Testing Library 12 uses all three, so the same test that was quiet on 18.0 prints three warnings on 18.3, without any change to the test.

### Will my tests need rewriting for Testing Library 16?

For `render`, `screen` and the queries, no; the imports and calls are the same as in 12. The changes between the two are in how the library mounts, which moved to `createRoot` and `React.act`, and in the `@testing-library/dom` peer dependency, which the pull request adds.

### Why not pin React back to 18.0?

Because the warning is a preview of React 19 removing those APIs. Pinning hides it until the major bump, when the suite stops working instead of warning. Upgrading the library now keeps the tests ready for 19.

### What about @testing-library/user-event?

It is not involved in this warning, and version 14 changed its API to asynchronous calls, which is its own change to review. The agent leaves it at 13 unless a test fails without it, and says so in the description.

## More jobs like this: Upgrade dependencies weekly

- [Fix the jsonschema RefResolver Deprecation Warning](https://getrush.ai/run/fix-refresolver-deprecation-warning/jsonschema/)
- [Fix "Using / for division outside of calc() is deprecated" in Sass](https://getrush.ai/run/fix-sass-division-deprecation/sass/)
- [Fix "Support for the test command was removed in Setuptools 72"](https://getrush.ai/run/fix-setup-py-test-command-removed/setuptools/)
- [Fix "The sphinxcontrib.applehelp extension used by this project needs at least Sphinx v5.0"](https://getrush.ai/run/fix-sphinxcontrib-applehelp-version-error/sphinx/)
- [Fix "The Default Datetime Adapter Is Deprecated as of Python 3.12" in a sqlite3 App](https://getrush.ai/run/fix-sqlite3-default-datetime-adapter-deprecated-warning/sqlite3/)
- [Fix "'Starlette' object has no attribute 'route'" After Upgrading to Starlette 1.0](https://getrush.ai/run/fix-starlette-object-has-no-attribute-route/starlette/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
