File tree Expand file tree Collapse file tree 2 files changed +20
-10
lines changed
Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,18 @@ test('cleanup runs effect cleanup functions', async () => {
4141 expect ( spy ) . toHaveBeenCalledTimes ( 1 )
4242} )
4343
44+ test ( 'cleanup cleans up every root and disconnects containers' , async ( ) => {
45+ const { container : container1 } = await render ( < div /> )
46+ const { container : container2 } = await render ( < span /> )
47+
48+ await cleanup ( )
49+
50+ expect ( container1 ) . toBeEmptyDOMElement ( )
51+ expect ( container1 . isConnected ) . toBe ( false )
52+ expect ( container2 ) . toBeEmptyDOMElement ( )
53+ expect ( container2 . isConnected ) . toBe ( false )
54+ } )
55+
4456describe ( 'fake timers and missing act warnings' , ( ) => {
4557 beforeEach ( ( ) => {
4658 jest . resetAllMocks ( )
Original file line number Diff line number Diff line change @@ -257,16 +257,14 @@ async function render(
257257}
258258
259259async function cleanup ( ) {
260- await Promise . all (
261- mountedRootEntries . map ( async ( { root, container} ) => {
262- await act ( ( ) => {
263- root . unmount ( )
264- } )
265- if ( container . parentNode === document . body ) {
266- document . body . removeChild ( container )
267- }
268- } ) ,
269- )
260+ for ( const { container, root} of mountedRootEntries ) {
261+ // eslint-disable-next-line no-await-in-loop -- Overlapping act calls are not allowed.
262+ await root . unmount ( )
263+ if ( container . parentNode === document . body ) {
264+ document . body . removeChild ( container )
265+ }
266+ }
267+
270268 mountedRootEntries . length = 0
271269 mountedContainers . clear ( )
272270}
You can’t perform that action at this time.
0 commit comments