| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @emails react-core |
| 8 | */ |
| 9 | |
| 10 | 'use strict'; |
| 11 | |
| 12 | describe('ReactDOMIframe', () => { |
| 13 | let React; |
| 14 | let ReactDOMClient; |
| 15 | let act; |
| 16 | |
| 17 | beforeEach(() => { |
| 18 | React = require('react'); |
| 19 | ReactDOMClient = require('react-dom/client'); |
| 20 | act = require('internal-test-utils').act; |
| 21 | }); |
| 22 | |
| 23 | it('should trigger load events', async () => { |
| 24 | const onLoadSpy = jest.fn(); |
| 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; |
| 31 | |
| 32 | const loadEvent = document.createEvent('Event'); |
| 33 | loadEvent.initEvent('load', false, false); |
| 34 | |
| 35 | await act(() => { |
| 36 | iframe.dispatchEvent(loadEvent); |
| 37 | }); |
| 38 | |
| 39 | expect(onLoadSpy).toHaveBeenCalled(); |
| 40 | }); |
| 41 | }); |