import { cleanup, render } from '@testing-library/react'; import { SWRConfig } from 'swr'; import { beforeEach, afterEach, vi } from 'vitest'; export const setupTestComponent = ( TestComponent: React.ComponentType, { init, }: { init?: (TestComponent: React.ComponentType) => React.ReactNode; } = {}, ) => { beforeEach(() => { // reset SWR cache to isolate tests: render( new Map() }}> {init?.(TestComponent) ?? } , ); }); afterEach(() => { vi.restoreAllMocks(); cleanup(); }); };