| title | react-dom/test-utils Deprecation Warnings |
|---|
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';All APIs except act have been removed.
The React Team recommends migrating your tests to @testing-library/react for a modern and well supported testing experience.
renderIntoDocument can be replaced with render from @testing-library/react.
Unlike renderIntoDocument, render gives you access to the rendered container and explicit cleanup APIs.
Before:
import {renderIntoDocument} from 'react-dom/test-utils';
renderIntoDocument(<Component />);After:
import {render} from '@testing-library/react';
render(<Component />);renderIntoDocument rendered into a detached DOM node and returned the component instance instead of the container.
This made it difficult to inspect the rendered output or reliably clean it up after a test.
render returns helpers for the rendered tree, including unmount, and React Testing Library also provides cleanup to remove any trees mounted with render between tests.
import {render} from '@testing-library/react';
test('renders a component', () => {
const {unmount} = render(<Component />);
// ...assertions...
unmount();
});Simulate can be replaced with fireEvent from @testing-library/react.
Before:
import {Simulate} from 'react-dom/test-utils';
const element = document.querySelector('button');
Simulate.click(element);After:
import {fireEvent} from '@testing-library/react';
const element = document.querySelector('button');
fireEvent.click(element);Be aware that fireEvent dispatches an actual event on the element and doesn't just synthetically call the event handler.
mockComponent()isElement()isElementOfType()isDOMComponent()isCompositeComponent()isCompositeComponentWithType()findAllInRenderedTree()scryRenderedDOMComponentsWithClass()findRenderedDOMComponentWithClass()scryRenderedDOMComponentsWithTag()findRenderedDOMComponentWithTag()scryRenderedComponentsWithType()findRenderedComponentWithType()renderIntoDocumentSimulate