@@ -4,11 +4,18 @@ title: react-dom/test-utils Deprecation Warnings
4
4
5
5
## ReactDOMTestUtils.act() warning {/* reactdomtestutilsact-warning* /}
6
6
7
- ` act ` from ` react-dom/test-utils ` has been deprecated in favor of ` act ` from ` react ` :
7
+ ` act ` from ` react-dom/test-utils ` has been deprecated in favor of ` act ` from ` react ` .
8
8
9
- ``` diff
10
- - import {act} from 'react-dom/test-utils';
11
- + import {act} from 'react';
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' ;
12
19
```
13
20
14
21
## Rest of ReactDOMTestUtils APIS {/* rest-of-reactdomtestutils-apis* /}
@@ -19,27 +26,44 @@ The React Team recommends migrating your tests to [@testing-library/react](https
19
26
20
27
### ReactDOMTestUtils.renderIntoDocument {/* reactdomtestutilsrenderintodocument* /}
21
28
22
- ` renderIntoDocument ` can be replaced with ` render ` from ` @testing-library/react ` :
29
+ ` renderIntoDocument ` can be replaced with ` render ` from ` @testing-library/react ` .
23
30
24
- ``` diff
25
- - import {renderIntoDocument} from 'react-dom/test-utils';
26
- + import {render} from '@testing-library/react';
31
+ Before:
27
32
28
- - renderIntoDocument(<Component />);
29
- + render(<Component />);
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 / > );
30
45
```
31
46
32
47
### ReactDOMTestUtils.Simulate {/* reactdomtestutilssimulate* /}
33
48
34
49
` Simulate ` can be replaced with ` fireEvent ` from ` @testing-library/react ` .
35
50
36
- ``` diff
37
- - import {Simulate} from 'react-dom/test-utils';
38
- + import {fireEvent} from '@testing-library/react';
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' ;
39
64
40
65
const element = document .querySelector (' button' );
41
- - Simulate.click(element);
42
- + fireEvent.click(element);
66
+ fireEvent .click (element);
43
67
```
44
68
45
69
Be aware, that ` fireEvent ` dispatches an actual event on the element and doesn't just synthetically call the event handler.
0 commit comments