1010'use strict' ;
1111
1212let React ;
13- let ReactDOM ;
13+ let ReactDOMClient ;
14+ let act ;
1415
1516describe ( 'BeforeInputEventPlugin' , ( ) => {
1617 let container ;
1718
18- function loadReactDOM ( envSimulator ) {
19+ function loadReactDOMClientAndAct ( envSimulator ) {
1920 jest . resetModules ( ) ;
2021 if ( envSimulator ) {
2122 envSimulator ( ) ;
2223 }
23- return require ( 'react-dom' ) ;
24+ return {
25+ ReactDOMClient : require ( 'react-dom/client' ) ,
26+ act : require ( 'internal-test-utils' ) . act ,
27+ } ;
2428 }
2529
2630 function simulateIE11 ( ) {
@@ -724,32 +728,36 @@ describe('BeforeInputEventPlugin', () => {
724728 } ,
725729 ] ;
726730
727- const testInputComponent = ( env , scenes ) => {
731+ const testInputComponent = async ( env , scenes ) => {
728732 let beforeInputEvent ;
729733 let compositionStartEvent ;
730734 let compositionUpdateEvent ;
731735 let spyOnBeforeInput ;
732736 let spyOnCompositionStart ;
733737 let spyOnCompositionUpdate ;
734- ReactDOM = loadReactDOM ( env . emulator ) ;
735- const node = ReactDOM . render (
736- < input
737- type = "text"
738- onBeforeInput = { e => {
739- spyOnBeforeInput ( ) ;
740- beforeInputEvent = e ;
741- } }
742- onCompositionStart = { e => {
743- spyOnCompositionStart ( ) ;
744- compositionStartEvent = e ;
745- } }
746- onCompositionUpdate = { e => {
747- spyOnCompositionUpdate ( ) ;
748- compositionUpdateEvent = e ;
749- } }
750- /> ,
751- container ,
752- ) ;
738+ ( { ReactDOMClient, act} = loadReactDOMClientAndAct ( env . emulator ) ) ;
739+ const root = ReactDOMClient . createRoot ( container ) ;
740+ await act ( ( ) => {
741+ root . render (
742+ < input
743+ type = "text"
744+ onBeforeInput = { e => {
745+ spyOnBeforeInput ( ) ;
746+ beforeInputEvent = e ;
747+ } }
748+ onCompositionStart = { e => {
749+ spyOnCompositionStart ( ) ;
750+ compositionStartEvent = e ;
751+ } }
752+ onCompositionUpdate = { e => {
753+ spyOnCompositionUpdate ( ) ;
754+ compositionUpdateEvent = e ;
755+ } }
756+ /> ,
757+ ) ;
758+ } ) ;
759+
760+ const node = container . firstChild ;
753761
754762 scenes . forEach ( ( s , id ) => {
755763 beforeInputEvent = null ;
@@ -770,32 +778,37 @@ describe('BeforeInputEventPlugin', () => {
770778 } ) ;
771779 } ;
772780
773- const testContentEditableComponent = ( env , scenes ) => {
781+ const testContentEditableComponent = async ( env , scenes ) => {
774782 let beforeInputEvent ;
775783 let compositionStartEvent ;
776784 let compositionUpdateEvent ;
777785 let spyOnBeforeInput ;
778786 let spyOnCompositionStart ;
779787 let spyOnCompositionUpdate ;
780- ReactDOM = loadReactDOM ( env . emulator ) ;
781- const node = ReactDOM . render (
782- < div
783- contentEditable = { true }
784- onBeforeInput = { e => {
785- spyOnBeforeInput ( ) ;
786- beforeInputEvent = e ;
787- } }
788- onCompositionStart = { e => {
789- spyOnCompositionStart ( ) ;
790- compositionStartEvent = e ;
791- } }
792- onCompositionUpdate = { e => {
793- spyOnCompositionUpdate ( ) ;
794- compositionUpdateEvent = e ;
795- } }
796- /> ,
797- container ,
798- ) ;
788+ ( { ReactDOMClient, act} = loadReactDOMClientAndAct ( env . emulator ) ) ;
789+ const root = ReactDOMClient . createRoot ( container ) ;
790+
791+ await act ( ( ) => {
792+ root . render (
793+ < div
794+ contentEditable = { true }
795+ onBeforeInput = { e => {
796+ spyOnBeforeInput ( ) ;
797+ beforeInputEvent = e ;
798+ } }
799+ onCompositionStart = { e => {
800+ spyOnCompositionStart ( ) ;
801+ compositionStartEvent = e ;
802+ } }
803+ onCompositionUpdate = { e => {
804+ spyOnCompositionUpdate ( ) ;
805+ compositionUpdateEvent = e ;
806+ } }
807+ /> ,
808+ ) ;
809+ } ) ;
810+
811+ const node = container . firstChild ;
799812
800813 scenes . forEach ( ( s , id ) => {
801814 beforeInputEvent = null ;
@@ -816,33 +829,33 @@ describe('BeforeInputEventPlugin', () => {
816829 } ) ;
817830 } ;
818831
819- it ( 'should extract onBeforeInput when simulating in Webkit on input[type=text]' , ( ) => {
820- testInputComponent ( environments [ 0 ] , scenarios ) ;
832+ it ( 'should extract onBeforeInput when simulating in Webkit on input[type=text]' , async ( ) => {
833+ await testInputComponent ( environments [ 0 ] , scenarios ) ;
821834 } ) ;
822- it ( 'should extract onBeforeInput when simulating in Webkit on contenteditable' , ( ) => {
823- testContentEditableComponent ( environments [ 0 ] , scenarios ) ;
835+ it ( 'should extract onBeforeInput when simulating in Webkit on contenteditable' , async ( ) => {
836+ await testContentEditableComponent ( environments [ 0 ] , scenarios ) ;
824837 } ) ;
825838
826- it ( 'should extract onBeforeInput when simulating in IE11 on input[type=text]' , ( ) => {
827- testInputComponent ( environments [ 1 ] , scenarios ) ;
839+ it ( 'should extract onBeforeInput when simulating in IE11 on input[type=text]' , async ( ) => {
840+ await testInputComponent ( environments [ 1 ] , scenarios ) ;
828841 } ) ;
829- it ( 'should extract onBeforeInput when simulating in IE11 on contenteditable' , ( ) => {
830- testContentEditableComponent ( environments [ 1 ] , scenarios ) ;
842+ it ( 'should extract onBeforeInput when simulating in IE11 on contenteditable' , async ( ) => {
843+ await testContentEditableComponent ( environments [ 1 ] , scenarios ) ;
831844 } ) ;
832845
833- it ( 'should extract onBeforeInput when simulating in env with no CompositionEvent on input[type=text]' , ( ) => {
834- testInputComponent ( environments [ 2 ] , scenarios ) ;
846+ it ( 'should extract onBeforeInput when simulating in env with no CompositionEvent on input[type=text]' , async ( ) => {
847+ await testInputComponent ( environments [ 2 ] , scenarios ) ;
835848 } ) ;
836849
837850 // in an environment using composition fallback onBeforeInput will not work
838851 // as expected on a contenteditable as keydown and keyup events are translated
839852 // to keypress events
840853
841- it ( 'should extract onBeforeInput when simulating in env with only CompositionEvent on input[type=text]' , ( ) => {
842- testInputComponent ( environments [ 3 ] , scenarios ) ;
854+ it ( 'should extract onBeforeInput when simulating in env with only CompositionEvent on input[type=text]' , async ( ) => {
855+ await testInputComponent ( environments [ 3 ] , scenarios ) ;
843856 } ) ;
844857
845- it ( 'should extract onBeforeInput when simulating in env with only CompositionEvent on contenteditable' , ( ) => {
846- testContentEditableComponent ( environments [ 3 ] , scenarios ) ;
858+ it ( 'should extract onBeforeInput when simulating in env with only CompositionEvent on contenteditable' , async ( ) => {
859+ await testContentEditableComponent ( environments [ 3 ] , scenarios ) ;
847860 } ) ;
848861} ) ;
0 commit comments