Open satheshrgs opened 4 years ago
Probably you have a typo here:
export const getValueFromHelper = () => store.getState.SomeReducer;
should be
export const getValueFromHelper = () => store.getState().SomeReducer;
Also you are referring to the global variable called store
in your getValueFromHelper function.
So here you have 2 options.
state
variable and pass the store as a parameter to the function (preferred, to avoid dependencies)helper.js
export const getValueFromHelper = (store) => store.getState.SomeReducer;
code.test.js
const store = mockStore({ SomeReducer:{} })
console.log(store.getState().SomeReducer); // Here value is correct
testFunction(store); // But here it returning original state value
code.js
export const testFunction(state) {
const res = getValueFromHelper(state);
console.log(res);
}
I have a scenario in which a method uses Store Helper to get State. When I try to test the function using the mock store which I have created, it uses the original store instance ( since it is in a helper file).
code.js
helper.js
code.test.js