import '@testing-library/jest-dom/vitest'; import { act } from '@testing-library/react'; import type * as Zustand from 'zustand'; import type { StateCreator, StoreApi } from 'zustand'; /* oxlint-disable functional/no-classes, no-unnecessary-condition -- jsdom 런타임에는 ResizeObserver가 없는데(전역 타입만 존재) radix(RadioGroup·Slider 등)가 마운트에서 new로 요구한다. 없으면 렌더 트리가 조용히 unmount돼 원인 특정이 어렵다(파일럿 실측). */ class ResizeObserverStub { observe(): void {} unobserve(): void {} disconnect(): void {} } globalThis.ResizeObserver ??= ResizeObserverStub; /* oxlint-enable functional/no-classes, no-unnecessary-condition */ const storeResetFns = new Set<() => void>(); vi.mock('zustand', async () => { const actual = await vi.importActual('zustand'); const track = >(store: S): S => { const initialState = store.getInitialState(); storeResetFns.add(() => { store.setState(initialState, true); }); return store; }; const create = (stateCreator?: StateCreator) => stateCreator === undefined ? (curried: StateCreator) => track(actual.create(curried)) : track(actual.create(stateCreator)); const createStore = (stateCreator?: StateCreator) => stateCreator === undefined ? (curried: StateCreator) => track(actual.createStore(curried)) : track(actual.createStore(stateCreator)); return { ...actual, create, createStore }; }); afterEach(() => { act(() => { storeResetFns.forEach((reset) => { reset(); }); }); });