1111
1212const React = require ( 'react' ) ;
1313const ReactDOM = require ( 'react-dom' ) ;
14+ const ReactDOMClient = require ( 'react-dom/client' ) ;
15+ const act = require ( 'internal-test-utils' ) . act ;
1416
1517describe ( 'ReactMount' , ( ) => {
16- it ( 'should destroy a react root upon request' , ( ) => {
18+ it ( 'should destroy a react root upon request' , async ( ) => {
1719 const mainContainerDiv = document . createElement ( 'div' ) ;
1820 document . body . appendChild ( mainContainerDiv ) ;
1921
2022 const instanceOne = < div className = "firstReactDiv" /> ;
2123 const firstRootDiv = document . createElement ( 'div' ) ;
2224 mainContainerDiv . appendChild ( firstRootDiv ) ;
23- ReactDOM . render ( instanceOne , firstRootDiv ) ;
25+ const firstRoot = ReactDOMClient . createRoot ( firstRootDiv ) ;
26+ await act ( ( ) => {
27+ firstRoot . render ( instanceOne ) ;
28+ } ) ;
2429
2530 const instanceTwo = < div className = "secondReactDiv" /> ;
2631 const secondRootDiv = document . createElement ( 'div' ) ;
2732 mainContainerDiv . appendChild ( secondRootDiv ) ;
28- ReactDOM . render ( instanceTwo , secondRootDiv ) ;
33+ const secondRoot = ReactDOMClient . createRoot ( secondRootDiv ) ;
34+ await act ( ( ) => {
35+ secondRoot . render ( instanceTwo ) ;
36+ } ) ;
2937
3038 // Test that two react roots are rendered in isolation
3139 expect ( firstRootDiv . firstChild . className ) . toBe ( 'firstReactDiv' ) ;
3240 expect ( secondRootDiv . firstChild . className ) . toBe ( 'secondReactDiv' ) ;
3341
3442 // Test that after unmounting each, they are no longer in the document.
35- ReactDOM . unmountComponentAtNode ( firstRootDiv ) ;
43+ await act ( ( ) => {
44+ firstRoot . unmount ( ) ;
45+ } ) ;
3646 expect ( firstRootDiv . firstChild ) . toBeNull ( ) ;
37- ReactDOM . unmountComponentAtNode ( secondRootDiv ) ;
38- expect ( secondRootDiv . firstChild ) . toBeNull ( ) ;
47+ await act ( ( ) => {
48+ secondRoot . unmount ( ) ;
49+ } ) ;
3950 } ) ;
4051
4152 it ( 'should warn when unmounting a non-container root node' , ( ) => {
@@ -46,6 +57,7 @@ describe('ReactMount', () => {
4657 < div />
4758 </ div >
4859 ) ;
60+ // Cannot be migrated to createRoot until we remove unmountComponentAtNode i.e. remove this test.
4961 ReactDOM . render ( component , mainContainerDiv ) ;
5062
5163 // Test that unmounting at a root node gives a helpful warning
@@ -69,6 +81,7 @@ describe('ReactMount', () => {
6981 </ div >
7082 </ div >
7183 ) ;
84+ // Cannot be migrated to createRoot until we remove unmountComponentAtNode i.e. remove this test.
7285 ReactDOM . render ( component , mainContainerDiv ) ;
7386
7487 // Test that unmounting at a non-root node gives a different warning
0 commit comments