File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
packages/react-dom/src/__tests__ Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,13 @@ describe('ReactDOMRoot', () => {
133133 expect ( container . textContent ) . toEqual ( '' ) ;
134134 } ) ;
135135
136+ it ( 'can be immediately unmounted' , async ( ) => {
137+ const root = ReactDOMClient . createRoot ( container ) ;
138+ await act ( ( ) => {
139+ root . unmount ( ) ;
140+ } ) ;
141+ } ) ;
142+
136143 it ( 'supports hydration' , async ( ) => {
137144 const markup = await new Promise ( resolve =>
138145 resolve (
@@ -392,6 +399,18 @@ describe('ReactDOMRoot', () => {
392399 }
393400 } ) ;
394401
402+ it ( 'throws if unmounting a root that has had its contents removed' , async ( ) => {
403+ const root = ReactDOMClient . createRoot ( container ) ;
404+ await act ( ( ) => {
405+ root . render ( < div > Hi</ div > ) ;
406+ } ) ;
407+ container . innerHTML = '' ;
408+
409+ expect ( ( ) => {
410+ root . unmount ( ) ;
411+ } ) . toThrow ( 'The node to be removed is not a child of this node.' ) ;
412+ } ) ;
413+
395414 it ( 'opts-in to concurrent default updates' , async ( ) => {
396415 const root = ReactDOMClient . createRoot ( container , {
397416 unstable_concurrentUpdatesByDefault : true ,
You can’t perform that action at this time.
0 commit comments