Cannot mock Zustand store – mockImplementation error #3083
Unanswered
201flaviosilva
asked this question in
Q&A
Replies: 1 comment
-
@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.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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:
Property 'mockImplementation' does not exist on type 'UseBoundStore<StoreApi<CounterState>>'.ts(2339)
Test:
How can I cleanly mock a Zustand store (useCounterStore) in Vitest while avoiding TypeScript issues with mockImplementation?
Is there a better approach for mocking Zustand in tests?
Here is a repository example setup: https://bitbucket.org/201flaviosilva-labs/mock-zustand-store/
Thanks
Beta Was this translation helpful? Give feedback.
All reactions