11import React , { Suspense } from 'react'
22import { act , create } from 'react-test-renderer'
3-
4- let cleanupCallbacks = [ ]
3+ import { cleanup , addCleanup , removeCleanup } from './cleanup'
54
65function TestHook ( { callback, hookProps, onError, children } ) {
76 try {
@@ -77,12 +76,12 @@ function renderHook(callback, { initialProps, wrapper } = {}) {
7776
7877 function unmountHook ( ) {
7978 act ( ( ) => {
80- cleanupCallbacks = cleanupCallbacks . filter ( ( cb ) => cb !== unmountHook )
79+ removeCleanup ( unmountHook )
8180 unmount ( )
8281 } )
8382 }
8483
85- cleanupCallbacks . push ( unmountHook )
84+ addCleanup ( unmountHook )
8685
8786 let waitingForNextUpdate = null
8887 const resolveOnNextUpdate = ( resolve ) => {
@@ -108,18 +107,4 @@ function renderHook(callback, { initialProps, wrapper } = {}) {
108107 }
109108}
110109
111- async function cleanup ( ) {
112- await act ( async ( ) => {
113- await act ( async ( ) => { } )
114- cleanupCallbacks . forEach ( ( cb ) => cb ( ) )
115- cleanupCallbacks = [ ]
116- } )
117- }
118-
119- if ( typeof afterEach === 'function' && ! process . env . RHTL_SKIP_AUTO_CLEANUP ) {
120- afterEach ( async ( ) => {
121- await cleanup ( )
122- } )
123- }
124-
125110export { renderHook , cleanup , act }
0 commit comments