10
10
'use strict' ;
11
11
12
12
let React ;
13
- let ReactDOM ;
13
+ let ReactDOMClient ;
14
+ let act ;
14
15
15
16
describe ( 'SyntheticWheelEvent' , ( ) => {
16
17
let container ;
18
+ let root ;
17
19
18
20
beforeEach ( ( ) => {
19
21
React = require ( 'react' ) ;
20
- ReactDOM = require ( 'react-dom' ) ;
22
+ ReactDOMClient = require ( 'react-dom/client' ) ;
23
+ act = require ( 'internal-test-utils' ) . act ;
21
24
22
25
// The container has to be attached for events to fire.
23
26
container = document . createElement ( 'div' ) ;
24
27
document . body . appendChild ( container ) ;
28
+ root = ReactDOMClient . createRoot ( container ) ;
25
29
} ) ;
26
30
27
31
afterEach ( ( ) => {
28
32
document . body . removeChild ( container ) ;
29
33
container = null ;
30
34
} ) ;
31
35
32
- it ( 'should normalize properties from the MouseEvent interface' , ( ) => {
36
+ it ( 'should normalize properties from the MouseEvent interface' , async ( ) => {
33
37
const events = [ ] ;
34
38
const onWheel = event => {
35
39
event . persist ( ) ;
36
40
events . push ( event ) ;
37
41
} ;
38
- ReactDOM . render ( < div onWheel = { onWheel } /> , container ) ;
42
+ await act ( async ( ) => {
43
+ root . render ( < div onWheel = { onWheel } /> ) ;
44
+ } ) ;
39
45
40
46
container . firstChild . dispatchEvent (
41
47
new MouseEvent ( 'wheel' , {
@@ -48,13 +54,16 @@ describe('SyntheticWheelEvent', () => {
48
54
expect ( events [ 0 ] . button ) . toBe ( 1 ) ;
49
55
} ) ;
50
56
51
- it ( 'should normalize properties from the WheelEvent interface' , ( ) => {
57
+ it ( 'should normalize properties from the WheelEvent interface' , async ( ) => {
52
58
const events = [ ] ;
53
59
const onWheel = event => {
54
60
event . persist ( ) ;
55
61
events . push ( event ) ;
56
62
} ;
57
- ReactDOM . render ( < div onWheel = { onWheel } /> , container ) ;
63
+
64
+ await act ( async ( ) => {
65
+ root . render ( < div onWheel = { onWheel } /> ) ;
66
+ } ) ;
58
67
59
68
let event = new MouseEvent ( 'wheel' , {
60
69
bubbles : true ,
@@ -83,7 +92,7 @@ describe('SyntheticWheelEvent', () => {
83
92
expect ( events [ 1 ] . deltaY ) . toBe ( - 50 ) ;
84
93
} ) ;
85
94
86
- it ( 'should be able to `preventDefault` and `stopPropagation`' , ( ) => {
95
+ it ( 'should be able to `preventDefault` and `stopPropagation`' , async ( ) => {
87
96
const events = [ ] ;
88
97
const onWheel = event => {
89
98
expect ( event . isDefaultPrevented ( ) ) . toBe ( false ) ;
@@ -92,7 +101,9 @@ describe('SyntheticWheelEvent', () => {
92
101
event . persist ( ) ;
93
102
events . push ( event ) ;
94
103
} ;
95
- ReactDOM . render ( < div onWheel = { onWheel } /> , container ) ;
104
+ await act ( async ( ) => {
105
+ root . render ( < div onWheel = { onWheel } /> ) ;
106
+ } ) ;
96
107
97
108
container . firstChild . dispatchEvent (
98
109
new MouseEvent ( 'wheel' , {
@@ -111,5 +122,6 @@ describe('SyntheticWheelEvent', () => {
111
122
) ;
112
123
113
124
expect ( events . length ) . toBe ( 2 ) ;
125
+ expect . assertions ( 5 ) ;
114
126
} ) ;
115
127
} ) ;
0 commit comments