File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
packages/react-dom/src/__tests__ Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change 11
11
12
12
describe ( 'ReactDOMIframe' , ( ) => {
13
13
let React ;
14
- let ReactTestUtils ;
14
+ let ReactDOMClient ;
15
+ let act ;
15
16
16
17
beforeEach ( ( ) => {
17
18
React = require ( 'react' ) ;
18
- ReactTestUtils = require ( 'react-dom/test-utils' ) ;
19
+ ReactDOMClient = require ( 'react-dom/client' ) ;
20
+ act = require ( 'internal-test-utils' ) . act ;
19
21
} ) ;
20
22
21
- it ( 'should trigger load events' , ( ) => {
23
+ it ( 'should trigger load events' , async ( ) => {
22
24
const onLoadSpy = jest . fn ( ) ;
23
- let iframe = React . createElement ( 'iframe' , { onLoad : onLoadSpy } ) ;
24
- iframe = ReactTestUtils . renderIntoDocument ( iframe ) ;
25
+ const container = document . createElement ( 'div' ) ;
26
+ const root = ReactDOMClient . createRoot ( container ) ;
27
+ await act ( ( ) => {
28
+ root . render ( React . createElement ( 'iframe' , { onLoad : onLoadSpy } ) ) ;
29
+ } ) ;
30
+ const iframe = container . firstChild ;
25
31
26
32
const loadEvent = document . createEvent ( 'Event' ) ;
27
33
loadEvent . initEvent ( 'load' , false , false ) ;
28
34
29
- iframe . dispatchEvent ( loadEvent ) ;
35
+ await act ( ( ) => {
36
+ iframe . dispatchEvent ( loadEvent ) ;
37
+ } ) ;
30
38
31
39
expect ( onLoadSpy ) . toHaveBeenCalled ( ) ;
32
40
} ) ;
You can’t perform that action at this time.
0 commit comments