diff --git a/packages/react-dom/src/__tests__/ReactDOMIframe-test.js b/packages/react-dom/src/__tests__/ReactDOMIframe-test.js index 2f3f03ad3df89..5ce6811b247b5 100644 --- a/packages/react-dom/src/__tests__/ReactDOMIframe-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMIframe-test.js @@ -11,22 +11,30 @@ describe('ReactDOMIframe', () => { let React; - let ReactTestUtils; + let ReactDOMClient; + let act; beforeEach(() => { React = require('react'); - ReactTestUtils = require('react-dom/test-utils'); + ReactDOMClient = require('react-dom/client'); + act = require('internal-test-utils').act; }); - it('should trigger load events', () => { + it('should trigger load events', async () => { const onLoadSpy = jest.fn(); - let iframe = React.createElement('iframe', {onLoad: onLoadSpy}); - iframe = ReactTestUtils.renderIntoDocument(iframe); + const container = document.createElement('div'); + const root = ReactDOMClient.createRoot(container); + await act(() => { + root.render(React.createElement('iframe', {onLoad: onLoadSpy})); + }); + const iframe = container.firstChild; const loadEvent = document.createEvent('Event'); loadEvent.initEvent('load', false, false); - iframe.dispatchEvent(loadEvent); + await act(() => { + iframe.dispatchEvent(loadEvent); + }); expect(onLoadSpy).toHaveBeenCalled(); });