redux-mock-store
redux-mock-store copied to clipboard
replaceReducer() does nothing.
When replaceReducer(someReducerFunction) is run, nothing is set in the mock store. Also, mock stores don't actually have a reducer to begin with.
@nhooey You can pass a function to the mockStore instead of object. It will receive all the dispatched actions, thus you can dynamically return new state from the dispatched actions and treat it as a reducer. Hope this will help.
reference: https://github.com/arnaudbenard/redux-mock-store/pull/109
I'm throwing an error when replaceReducer is called on my TypeScript fork, @jedmao/redux-mock-store.
Why is there a refusal to allow this library to use a reducer as is?
Any progress on that?
all replaceReducer does is throw an error if you do not pass a function... https://github.com/reduxjs/redux-mock-store/blob/master/src/index.js#L66 that is it! this is a little confusing. one might expect it to do something. might be better to just remove it
You can pass a function to the mockStore instead of object. It will receive all the dispatched actions, thus you can dynamically return new state from the dispatched actions and treat it as a reducer. Hope this will help.
🤔 ...i found it useful to create a mini-redux like this.
const initialState = { slice: [{}] }
let currentState = initialState;
const mockStore = configureStore([middleware])(actions => {
const action = actions[actions.length - 1];
currentState = { ...currentState, slice: sliceReducer(currentState.slice, action) };
return currentState;
});