`ReactDOMTestUtils.act` is deprecated
angelod1as opened this issue · comments
@testing-library/jest-dom
version: ^6.4.5- Testing Framework and version:
"babel-jest": "^29.7.0",
"ts-jest": "^29.1.2",
"jest": "^29.7.0",
"jest-css-modules": "^2.1.0",
"jest-environment-jsdom": "^29.7.0",
"jest-google-maps-mock": "^1.0.7",
"jest-next-dynamic": "^1.0.1",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.5.2",
Relevant code or config:
This is the error in my console:
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.
39 | ui: React.ReactElement,
40 | options?: Omit<RenderOptions, "queries">,
> 41 | ) => render(ui, { wrapper: AllTheProviders, ...options })
| ^
42 |
43 | export * from "@testing-library/react"
44 |
at printWarning (node_modules/react-dom/cjs/react-dom-test-utils.development.js:71:30)
at error (node_modules/react-dom/cjs/react-dom-test-utils.development.js:45:7)
at actWithWarning (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1736:7)
at node_modules/@testing-library/react/dist/act-compat.js:63:25
at renderRoot (node_modules/@testing-library/react/dist/pure.js:159:26)
at render (node_modules/@testing-library/react/dist/pure.js:246:10)
at customRender (src/tests/index.tsx:41:12)
at Object.<anonymous> (src/components/common/input/Input.test.tsx:7:60)
This is my custom render.
import { render, RenderOptions } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
const customRender = (
ui: React.ReactElement,
options?: Omit<RenderOptions, "queries">,
) => render(ui, { wrapper: AllTheProviders, ...options })
export * from "@testing-library/react"
export { customRender as render, userEvent }
What you did:
I have a test file that exports a custom render function.
What happened:
It was working properly and now it throws the error above.
Reproduction:
I couldn't reproduce :(
Problem description:
Apparently Testing Library is importing from react-dom/test-utils
, which is deprecated.
From the docs:
ReactDOMTestUtils.act() warning
act from react-dom/test-utils has been deprecated in favor of act from react.
Before:
import {act} from 'react-dom/test-utils';
After:
import {act} from 'react';
Suggested solution:
Update the files to import act
from react
.
Fixed in @testing-library/react@^15.0.6