1010'use strict' ;
1111
1212let React ;
13- let ReactDOM ;
13+ let ReactDOMClient ;
14+ let act ;
1415
1516describe ( 'SelectEventPlugin' , ( ) => {
1617 let container ;
1718
1819 beforeEach ( ( ) => {
1920 React = require ( 'react' ) ;
20- ReactDOM = require ( 'react-dom' ) ;
21-
21+ ReactDOMClient = require ( 'react-dom/client ' ) ;
22+ act = require ( 'internal-test-utils' ) . act ;
2223 container = document . createElement ( 'div' ) ;
2324 document . body . appendChild ( container ) ;
2425 } ) ;
@@ -29,7 +30,7 @@ describe('SelectEventPlugin', () => {
2930 } ) ;
3031
3132 // See https://github.com/facebook/react/pull/3639 for details.
32- it ( 'does not get confused when dependent events are registered independently' , ( ) => {
33+ it ( 'does not get confused when dependent events are registered independently' , async ( ) => {
3334 const select = jest . fn ( ) ;
3435 const onSelect = event => {
3536 expect ( typeof event ) . toBe ( 'object' ) ;
@@ -38,11 +39,14 @@ describe('SelectEventPlugin', () => {
3839 select ( event . currentTarget ) ;
3940 } ;
4041
41- // Pass `onMouseDown` so React registers a top-level listener.
42- const node = ReactDOM . render (
43- < input type = "text" onMouseDown = { function ( ) { } } /> ,
44- container ,
45- ) ;
42+ const root = ReactDOMClient . createRoot ( container ) ;
43+ const node = await ( async function ( ) {
44+ await act ( ( ) => {
45+ // Pass `onMouseDown` so React registers a top-level listener.
46+ root . render ( < input type = "text" onMouseDown = { function ( ) { } } /> ) ;
47+ } ) ;
48+ return container . firstChild ;
49+ } ) ( ) ;
4650
4751 // Trigger `mousedown` and `mouseup`. Note that
4852 // React is not currently listening to `mouseup`.
@@ -59,8 +63,10 @@ describe('SelectEventPlugin', () => {
5963 } ) ,
6064 ) ;
6165
62- // Now subscribe to `onSelect`.
63- ReactDOM . render ( < input type = "text" onSelect = { onSelect } /> , container ) ;
66+ await act ( ( ) => {
67+ // Now subscribe to `onSelect`
68+ root . render ( < input type = "text" onSelect = { onSelect } /> ) ;
69+ } ) ;
6470 node . focus ( ) ;
6571
6672 // This triggers a `select` event in our polyfill.
@@ -74,7 +80,7 @@ describe('SelectEventPlugin', () => {
7480 expect ( select ) . toHaveBeenCalledTimes ( 1 ) ;
7581 } ) ;
7682
77- it ( 'should fire `onSelect` when a listener is present' , ( ) => {
83+ it ( 'should fire `onSelect` when a listener is present' , async ( ) => {
7884 const select = jest . fn ( ) ;
7985 const onSelect = event => {
8086 expect ( typeof event ) . toBe ( 'object' ) ;
@@ -83,10 +89,14 @@ describe('SelectEventPlugin', () => {
8389 select ( event . currentTarget ) ;
8490 } ;
8591
86- const node = ReactDOM . render (
87- < input type = "text" onSelect = { onSelect } /> ,
88- container ,
89- ) ;
92+ const node = await ( async function ( ) {
93+ const root = ReactDOMClient . createRoot ( container ) ;
94+ await act ( ( ) => {
95+ root . render ( < input type = "text" onSelect = { onSelect } /> ) ;
96+ } ) ;
97+ return container . firstChild ;
98+ } ) ( ) ;
99+
90100 node . focus ( ) ;
91101
92102 let nativeEvent = new MouseEvent ( 'focus' , {
@@ -108,7 +118,7 @@ describe('SelectEventPlugin', () => {
108118 expect ( select ) . toHaveBeenCalledTimes ( 1 ) ;
109119 } ) ;
110120
111- it ( 'should fire `onSelectCapture` when a listener is present' , ( ) => {
121+ it ( 'should fire `onSelectCapture` when a listener is present' , async ( ) => {
112122 const select = jest . fn ( ) ;
113123 const onSelectCapture = event => {
114124 expect ( typeof event ) . toBe ( 'object' ) ;
@@ -117,10 +127,14 @@ describe('SelectEventPlugin', () => {
117127 select ( event . currentTarget ) ;
118128 } ;
119129
120- const node = ReactDOM . render (
121- < input type = "text" onSelectCapture = { onSelectCapture } /> ,
122- container ,
123- ) ;
130+ const node = await ( async function ( ) {
131+ const root = ReactDOMClient . createRoot ( container ) ;
132+ await act ( ( ) => {
133+ root . render ( < input type = "text" onSelectCapture = { onSelectCapture } /> ) ;
134+ } ) ;
135+ return container . firstChild ;
136+ } ) ( ) ;
137+
124138 node . focus ( ) ;
125139
126140 let nativeEvent = new MouseEvent ( 'focus' , {
@@ -143,7 +157,7 @@ describe('SelectEventPlugin', () => {
143157 } ) ;
144158
145159 // Regression test for https://github.com/facebook/react/issues/11379
146- it ( 'should not wait for `mouseup` after receiving `dragend`' , ( ) => {
160+ it ( 'should not wait for `mouseup` after receiving `dragend`' , async ( ) => {
147161 const select = jest . fn ( ) ;
148162 const onSelect = event => {
149163 expect ( typeof event ) . toBe ( 'object' ) ;
@@ -152,10 +166,14 @@ describe('SelectEventPlugin', () => {
152166 select ( event . currentTarget ) ;
153167 } ;
154168
155- const node = ReactDOM . render (
156- < input type = "text" onSelect = { onSelect } /> ,
157- container ,
158- ) ;
169+ const node = await ( async function ( ) {
170+ const root = ReactDOMClient . createRoot ( container ) ;
171+ await act ( ( ) => {
172+ root . render ( < input type = "text" onSelect = { onSelect } /> ) ;
173+ } ) ;
174+ return container . firstChild ;
175+ } ) ( ) ;
176+
159177 node . focus ( ) ;
160178
161179 let nativeEvent = new MouseEvent ( 'focus' , {
@@ -177,12 +195,17 @@ describe('SelectEventPlugin', () => {
177195 expect ( select ) . toHaveBeenCalledTimes ( 1 ) ;
178196 } ) ;
179197
180- it ( 'should handle selectionchange events' , function ( ) {
198+ it ( 'should handle selectionchange events' , async function ( ) {
181199 const onSelect = jest . fn ( ) ;
182- const node = ReactDOM . render (
183- < input type = "text" onSelect = { onSelect } /> ,
184- container ,
185- ) ;
200+
201+ const node = await ( async function ( ) {
202+ const root = ReactDOMClient . createRoot ( container ) ;
203+ await act ( ( ) => {
204+ root . render ( < input type = "text" onSelect = { onSelect } /> ) ;
205+ } ) ;
206+ return container . firstChild ;
207+ } ) ( ) ;
208+
186209 node . focus ( ) ;
187210
188211 // Make sure the event was not called before we emit the selection change event
0 commit comments