1717
1818let  PropTypes ; 
1919let  React ; 
20- let  ReactDOM ; 
20+ let  ReactDOMClient ; 
2121let  ReactDOMServer ; 
2222let  ReactTestUtils ; 
23+ let  act ; 
2324
2425describe ( 'ReactContextValidator' ,  ( )  =>  { 
2526  beforeEach ( ( )  =>  { 
2627    jest . resetModules ( ) ; 
2728
2829    PropTypes  =  require ( 'prop-types' ) ; 
2930    React  =  require ( 'react' ) ; 
30-     ReactDOM  =  require ( 'react-dom' ) ; 
31+     ReactDOMClient  =  require ( 'react-dom/client ' ) ; 
3132    ReactDOMServer  =  require ( 'react-dom/server' ) ; 
3233    ReactTestUtils  =  require ( 'react-dom/test-utils' ) ; 
34+     act  =  require ( 'internal-test-utils' ) . act ; 
3335  } ) ; 
3436
3537  // TODO: This behavior creates a runtime dependency on propTypes. We should 
@@ -72,7 +74,7 @@ describe('ReactContextValidator', () => {
7274  } ) ; 
7375
7476  // @gate  !disableLegacyContext 
75-   it ( 'should pass next context to lifecycles' ,  ( )  =>  { 
77+   it ( 'should pass next context to lifecycles' ,  async   ( )  =>  { 
7678    let  componentDidMountContext ; 
7779    let  componentDidUpdateContext ; 
7880    let  componentWillReceivePropsContext ; 
@@ -135,11 +137,18 @@ describe('ReactContextValidator', () => {
135137    } ; 
136138
137139    const  container  =  document . createElement ( 'div' ) ; 
138-     ReactDOM . render ( < Parent  foo = "abc"  /> ,  container ) ; 
140+     const  root  =  ReactDOMClient . createRoot ( container ) ; 
141+     await  act ( ( )  =>  { 
142+       root . render ( < Parent  foo = "abc"  /> ) ; 
143+     } ) ; 
144+ 
139145    expect ( constructorContext ) . toEqual ( { foo : 'abc' } ) ; 
140146    expect ( renderContext ) . toEqual ( { foo : 'abc' } ) ; 
141147    expect ( componentDidMountContext ) . toEqual ( { foo : 'abc' } ) ; 
142-     ReactDOM . render ( < Parent  foo = "def"  /> ,  container ) ; 
148+     await  act ( ( )  =>  { 
149+       root . render ( < Parent  foo = "def"  /> ) ; 
150+     } ) ; 
151+ 
143152    expect ( componentWillReceivePropsContext ) . toEqual ( { foo : 'abc' } ) ; 
144153    expect ( componentWillReceivePropsNextContext ) . toEqual ( { foo : 'def' } ) ; 
145154    expect ( shouldComponentUpdateContext ) . toEqual ( { foo : 'abc' } ) ; 
@@ -369,7 +378,7 @@ describe('ReactContextValidator', () => {
369378    expect ( childContext . foo ) . toBe ( 'FOO' ) ; 
370379  } ) ; 
371380
372-   it ( 'should pass next context to lifecycles' ,  ( )  =>  { 
381+   it ( 'should pass next context to lifecycles' ,  async   ( )  =>  { 
373382    let  componentDidMountContext ; 
374383    let  componentDidUpdateContext ; 
375384    let  componentWillReceivePropsContext ; 
@@ -417,21 +426,26 @@ describe('ReactContextValidator', () => {
417426    const  secondContext  =  { bar : 456 } ; 
418427
419428    const  container  =  document . createElement ( 'div' ) ; 
420-     ReactDOM . render ( 
421-       < Context . Provider  value = { firstContext } > 
422-         < Component  /> 
423-       </ Context . Provider > , 
424-       container , 
425-     ) ; 
429+     const  root  =  ReactDOMClient . createRoot ( container ) ; 
430+     await  act ( ( )  =>  { 
431+       root . render ( 
432+         < Context . Provider  value = { firstContext } > 
433+           < Component  /> 
434+         </ Context . Provider > , 
435+       ) ; 
436+     } ) ; 
437+ 
426438    expect ( constructorContext ) . toBe ( firstContext ) ; 
427439    expect ( renderContext ) . toBe ( firstContext ) ; 
428440    expect ( componentDidMountContext ) . toBe ( firstContext ) ; 
429-     ReactDOM . render ( 
430-       < Context . Provider  value = { secondContext } > 
431-         < Component  /> 
432-       </ Context . Provider > , 
433-       container , 
434-     ) ; 
441+     await  act ( ( )  =>  { 
442+       root . render ( 
443+         < Context . Provider  value = { secondContext } > 
444+           < Component  /> 
445+         </ Context . Provider > , 
446+       ) ; 
447+     } ) ; 
448+ 
435449    expect ( componentWillReceivePropsContext ) . toBe ( firstContext ) ; 
436450    expect ( componentWillReceivePropsNextContext ) . toBe ( secondContext ) ; 
437451    expect ( componentWillUpdateContext ) . toBe ( firstContext ) ; 
@@ -447,7 +461,7 @@ describe('ReactContextValidator', () => {
447461    } 
448462  } ) ; 
449463
450-   it ( 'should re-render PureComponents when context Provider updates' ,  ( )  =>  { 
464+   it ( 'should re-render PureComponents when context Provider updates' ,  async   ( )  =>  { 
451465    let  renderedContext ; 
452466
453467    const  Context  =  React . createContext ( ) ; 
@@ -464,19 +478,24 @@ describe('ReactContextValidator', () => {
464478    const  secondContext  =  { bar : 456 } ; 
465479
466480    const  container  =  document . createElement ( 'div' ) ; 
467-     ReactDOM . render ( 
468-       < Context . Provider  value = { firstContext } > 
469-         < Component  /> 
470-       </ Context . Provider > , 
471-       container , 
472-     ) ; 
481+     const  root  =  ReactDOMClient . createRoot ( container ) ; 
482+     await  act ( ( )  =>  { 
483+       root . render ( 
484+         < Context . Provider  value = { firstContext } > 
485+           < Component  /> 
486+         </ Context . Provider > , 
487+       ) ; 
488+     } ) ; 
489+ 
473490    expect ( renderedContext ) . toBe ( firstContext ) ; 
474-     ReactDOM . render ( 
475-       < Context . Provider  value = { secondContext } > 
476-         < Component  /> 
477-       </ Context . Provider > , 
478-       container , 
479-     ) ; 
491+     await  act ( ( )  =>  { 
492+       root . render ( 
493+         < Context . Provider  value = { secondContext } > 
494+           < Component  /> 
495+         </ Context . Provider > , 
496+       ) ; 
497+     } ) ; 
498+ 
480499    expect ( renderedContext ) . toBe ( secondContext ) ; 
481500  } ) ; 
482501
0 commit comments