Cannot mock Zustand store – mockImplementation error #3083
-
Hey everyone! 👋 I’m trying to mock a Zustand store in a Vitest + React Testing Library setup, but I’m running into the same TypeScript. Error: Test: vi.mock("./count.store", () => ({
useCounterStore: vi.fn(),
}));
beforeEach(() => {
useCounterStore.mockImplementation(() => mockStore);
}); How can I cleanly mock a Zustand store (useCounterStore) in Vitest while avoiding TypeScript issues with mockImplementation? Here is a repository example setup: https://bitbucket.org/201flaviosilva-labs/mock-zustand-store/ Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@201flaviosilva would you mind creating a minimal repro on stackblitz? btw, few things you need to follow on testing:
To reset states before each test: const createResetStore = (useStoreHook) => {
const initialState = storeHook.getInitialState()
useStoreHook.setState(initialState, true)
} const resetBearStore = createResetStore(useBearStore)
beforeEach(() => {
resetBearStore()
}) |
Beta Was this translation helpful? Give feedback.
@201flaviosilva here you go -> https://stackblitz.com/edit/vitejs-vite-ymcuqfgt?file=src%2FCounter%2FCounter.integration.test.tsx