|
9 | 9 |
|
10 | 10 | describe('SyntheticFocusEvent', () => { |
11 | 11 | let React; |
12 | | - let ReactDOM; |
| 12 | + let ReactDOMClient; |
| 13 | + let act; |
13 | 14 | let container; |
14 | 15 |
|
15 | 16 | beforeEach(() => { |
16 | 17 | jest.resetModules(); |
17 | 18 | React = require('react'); |
18 | | - ReactDOM = require('react-dom'); |
| 19 | + ReactDOMClient = require('react-dom/client'); |
| 20 | + act = require('internal-test-utils').act; |
19 | 21 |
|
20 | 22 | container = document.createElement('div'); |
21 | 23 | document.body.appendChild(container); |
@@ -26,44 +28,54 @@ describe('SyntheticFocusEvent', () => { |
26 | 28 | container = null; |
27 | 29 | }); |
28 | 30 |
|
29 | | - test('onFocus events have the focus type', () => { |
| 31 | + test('onFocus events have the focus type', async () => { |
30 | 32 | const log = []; |
31 | | - ReactDOM.render( |
32 | | - <button |
33 | | - onFocus={event => log.push(`onFocus: ${event.type}`)} |
34 | | - onFocusCapture={event => log.push(`onFocusCapture: ${event.type}`)} |
35 | | - />, |
36 | | - container, |
37 | | - ); |
| 33 | + const root = ReactDOMClient.createRoot(container); |
| 34 | + await act(() => { |
| 35 | + root.render( |
| 36 | + <button |
| 37 | + onFocus={event => log.push(`onFocus: ${event.type}`)} |
| 38 | + onFocusCapture={event => log.push(`onFocusCapture: ${event.type}`)} |
| 39 | + />, |
| 40 | + ); |
| 41 | + }); |
| 42 | + |
38 | 43 | const button = container.querySelector('button'); |
39 | 44 |
|
40 | | - button.dispatchEvent( |
41 | | - new FocusEvent('focusin', { |
42 | | - bubbles: true, |
43 | | - cancelable: false, |
44 | | - }), |
45 | | - ); |
| 45 | + await act(() => { |
| 46 | + button.dispatchEvent( |
| 47 | + new FocusEvent('focusin', { |
| 48 | + bubbles: true, |
| 49 | + cancelable: false, |
| 50 | + }), |
| 51 | + ); |
| 52 | + }); |
46 | 53 |
|
47 | 54 | expect(log).toEqual(['onFocusCapture: focus', 'onFocus: focus']); |
48 | 55 | }); |
49 | 56 |
|
50 | | - test('onBlur events have the blur type', () => { |
| 57 | + test('onBlur events have the blur type', async () => { |
51 | 58 | const log = []; |
52 | | - ReactDOM.render( |
53 | | - <button |
54 | | - onBlur={event => log.push(`onBlur: ${event.type}`)} |
55 | | - onBlurCapture={event => log.push(`onBlurCapture: ${event.type}`)} |
56 | | - />, |
57 | | - container, |
58 | | - ); |
| 59 | + const root = ReactDOMClient.createRoot(container); |
| 60 | + await act(() => { |
| 61 | + root.render( |
| 62 | + <button |
| 63 | + onBlur={event => log.push(`onBlur: ${event.type}`)} |
| 64 | + onBlurCapture={event => log.push(`onBlurCapture: ${event.type}`)} |
| 65 | + />, |
| 66 | + ); |
| 67 | + }); |
| 68 | + |
59 | 69 | const button = container.querySelector('button'); |
60 | 70 |
|
61 | | - button.dispatchEvent( |
62 | | - new FocusEvent('focusout', { |
63 | | - bubbles: true, |
64 | | - cancelable: false, |
65 | | - }), |
66 | | - ); |
| 71 | + await act(() => { |
| 72 | + button.dispatchEvent( |
| 73 | + new FocusEvent('focusout', { |
| 74 | + bubbles: true, |
| 75 | + cancelable: false, |
| 76 | + }), |
| 77 | + ); |
| 78 | + }); |
67 | 79 |
|
68 | 80 | expect(log).toEqual(['onBlurCapture: blur', 'onBlur: blur']); |
69 | 81 | }); |
|