UNPKG

@testing-library/react-hooks

Version:

Simple and complete React hooks testing utilities that encourage good testing practices.

27 lines (20 loc) 615 B
import { act } from 'react-test-renderer' let cleanupCallbacks = [] async function cleanup() { await act(async () => {}) cleanupCallbacks.forEach((cb) => cb()) cleanupCallbacks = [] } function addCleanup(callback) { cleanupCallbacks.push(callback) } function removeCleanup(callback) { cleanupCallbacks = cleanupCallbacks.filter((cb) => cb !== callback) } // Automatically registers cleanup in supported testing frameworks if (typeof afterEach === 'function' && !process.env.RHTL_SKIP_AUTO_CLEANUP) { afterEach(async () => { await cleanup() }) } export { cleanup, addCleanup, removeCleanup }