Skip to content

Commit 2aa9594

Browse files
authored
Add warning page for ReactDOMTestUtils deprecation (#6716)
1 parent 4df3124 commit 2aa9594

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: react-dom/test-utils Deprecation Warnings
3+
---
4+
5+
## ReactDOMTestUtils.act() warning {/*reactdomtestutilsact-warning*/}
6+
7+
`act` from `react-dom/test-utils` has been deprecated in favor of `act` from `react`.
8+
9+
Before:
10+
11+
```js
12+
import {act} from 'react-dom/test-utils';
13+
```
14+
15+
After:
16+
17+
```js
18+
import {act} from 'react';
19+
```
20+
21+
## Rest of ReactDOMTestUtils APIS {/*rest-of-reactdomtestutils-apis*/}
22+
23+
All APIs except `act` have been removed.
24+
25+
The React Team recommends migrating your tests to [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro/) for a modern and well supported testing experience.
26+
27+
### ReactDOMTestUtils.renderIntoDocument {/*reactdomtestutilsrenderintodocument*/}
28+
29+
`renderIntoDocument` can be replaced with `render` from `@testing-library/react`.
30+
31+
Before:
32+
33+
```js
34+
import {renderIntoDocument} from 'react-dom/test-utils';
35+
36+
renderIntoDocument(<Component />);
37+
```
38+
39+
After:
40+
41+
```js
42+
import {render} from '@testing-library/react';
43+
44+
render(<Component />);
45+
```
46+
47+
### ReactDOMTestUtils.Simulate {/*reactdomtestutilssimulate*/}
48+
49+
`Simulate` can be replaced with `fireEvent` from `@testing-library/react`.
50+
51+
Before:
52+
53+
```js
54+
import {Simulate} from 'react-dom/test-utils';
55+
56+
const element = document.querySelector('button');
57+
Simulate.click(element);
58+
```
59+
60+
After:
61+
62+
```js
63+
import {fireEvent} from '@testing-library/react';
64+
65+
const element = document.querySelector('button');
66+
fireEvent.click(element);
67+
```
68+
69+
Be aware that `fireEvent` dispatches an actual event on the element and doesn't just synthetically call the event handler.
70+
71+
### List of all removed APIs {/*list-of-all-removed-apis-list-of-all-removed-apis*/}
72+
73+
- `mockComponent()`
74+
- `isElement()`
75+
- `isElementOfType()`
76+
- `isDOMComponent()`
77+
- `isCompositeComponent()`
78+
- `isCompositeComponentWithType()`
79+
- `findAllInRenderedTree()`
80+
- `scryRenderedDOMComponentsWithClass()`
81+
- `findRenderedDOMComponentWithClass()`
82+
- `scryRenderedDOMComponentsWithTag()`
83+
- `findRenderedDOMComponentWithTag()`
84+
- `scryRenderedComponentsWithType()`
85+
- `findRenderedComponentWithType()`
86+
- `renderIntoDocument`
87+
- `Simulate`

0 commit comments

Comments
 (0)