Zustand testing throws an error "TypeError: store.getState is not a function"
See original GitHub issueIn the documentation it states that adding this in JEST would enable testing for ZUSTAND state.
const create = createState => {
const store = actualCreate(createState);
const initialState = store.getState();
storeResetFns.add(() => store.setState(initialState, true));
return store;
};
But it seems to throw an error “TypeError: store.getState is not a function”
I am using typescript not sure if this causes some issues. Also, it is not well documented on how to use this test in jest. Just want to have values on my states so that they can be used on my componentes during rendering of test components.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
reactjs - _this.store.getState is not a function when testing ...
This error means that store can't get the state correctly. I would recommend mocking the store using redux-mock-store and import ...
Read more >React Testing Library and the “not wrapped in act” Errors
I recently upgraded React and React testing library. Very happy about the upgrade. But I start to see test errors like this: In...
Read more >TypeScript Guide - Zustand Documentation
Zustand is a small, fast and scalable bearbones state-management solution, it has a comfy api based on hooks.
Read more >zustand - Bountysource
TypeError : store.getState is not a function import { act } from 'react-dom/test-utils'; import actualCreate from 'zustand'; // a variable to hold reset ......
Read more >React - How to fix this.setState is not a function error
This error happens when JavaScript can't find the setState() function from the context of this keyword. There are two ways to fix this...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ohh nevermind I got it:
To do this you should use the actual store of your app
Can close now??