Skip to content

Commit

Permalink
Convert ReactDOMIframe to createRoot (#28197)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored and gaearon committed Feb 3, 2024
1 parent 84a1a0c commit 8e4fc87
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/react-dom/src/__tests__/ReactDOMIframe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit 8e4fc87

Please sign in to comment.