@@ -13,13 +13,15 @@ jest.mock('react-dom-bindings/src/events/isEventSupported');
13
13
14
14
describe ( 'InvalidEventListeners' , ( ) => {
15
15
let React ;
16
- let ReactDOM ;
16
+ let ReactDOMClient ;
17
+ let act ;
17
18
let container ;
18
19
19
20
beforeEach ( ( ) => {
20
21
jest . resetModules ( ) ;
21
22
React = require ( 'react' ) ;
22
- ReactDOM = require ( 'react-dom' ) ;
23
+ ReactDOMClient = require ( 'react-dom/client' ) ;
24
+ act = require ( 'internal-test-utils' ) . act ;
23
25
24
26
container = document . createElement ( 'div' ) ;
25
27
document . body . appendChild ( container ) ;
@@ -30,13 +32,16 @@ describe('InvalidEventListeners', () => {
30
32
container = null ;
31
33
} ) ;
32
34
33
- it ( 'should prevent non-function listeners, at dispatch' , ( ) => {
34
- let node ;
35
- expect ( ( ) => {
36
- node = ReactDOM . render ( < div onClick = "not a function" /> , container ) ;
35
+ it ( 'should prevent non-function listeners, at dispatch' , async ( ) => {
36
+ const root = ReactDOMClient . createRoot ( container ) ;
37
+ await expect ( async ( ) => {
38
+ await act ( ( ) => {
39
+ root . render ( < div onClick = "not a function" /> ) ;
40
+ } ) ;
37
41
} ) . toErrorDev (
38
42
'Expected `onClick` listener to be a function, instead got a value of `string` type.' ,
39
43
) ;
44
+ const node = container . firstChild ;
40
45
41
46
spyOnProd ( console , 'error' ) ;
42
47
@@ -46,11 +51,13 @@ describe('InvalidEventListeners', () => {
46
51
}
47
52
window . addEventListener ( 'error' , handleWindowError ) ;
48
53
try {
49
- node . dispatchEvent (
50
- new MouseEvent ( 'click' , {
51
- bubbles : true ,
52
- } ) ,
53
- ) ;
54
+ await act ( ( ) => {
55
+ node . dispatchEvent (
56
+ new MouseEvent ( 'click' , {
57
+ bubbles : true ,
58
+ } ) ,
59
+ ) ;
60
+ } ) ;
54
61
} finally {
55
62
window . removeEventListener ( 'error' , handleWindowError ) ;
56
63
}
@@ -77,12 +84,19 @@ describe('InvalidEventListeners', () => {
77
84
}
78
85
} ) ;
79
86
80
- it ( 'should not prevent null listeners, at dispatch' , ( ) => {
81
- const node = ReactDOM . render ( < div onClick = { null } /> , container ) ;
82
- node . dispatchEvent (
83
- new MouseEvent ( 'click' , {
84
- bubbles : true ,
85
- } ) ,
86
- ) ;
87
+ it ( 'should not prevent null listeners, at dispatch' , async ( ) => {
88
+ const root = ReactDOMClient . createRoot ( container ) ;
89
+ await act ( ( ) => {
90
+ root . render ( < div onClick = { null } /> ) ;
91
+ } ) ;
92
+
93
+ const node = container . firstChild ;
94
+ await act ( ( ) => {
95
+ node . dispatchEvent (
96
+ new MouseEvent ( 'click' , {
97
+ bubbles : true ,
98
+ } ) ,
99
+ ) ;
100
+ } ) ;
87
101
} ) ;
88
102
} ) ;
0 commit comments