Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaceReducer() does nothing. #145

Open
nhooey opened this issue Mar 26, 2018 · 5 comments
Open

replaceReducer() does nothing. #145

nhooey opened this issue Mar 26, 2018 · 5 comments

Comments

@nhooey
Copy link

nhooey commented Mar 26, 2018

When replaceReducer(someReducerFunction) is run, nothing is set in the mock store. Also, mock stores don't actually have a reducer to begin with.

@metreniuk
Copy link

@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: #109

@jednano
Copy link

jednano commented Jul 12, 2019

I'm throwing an error when replaceReducer is called on my TypeScript fork, @jedmao/redux-mock-store.

@baileytincher
Copy link

Why is there a refusal to allow this library to use a reducer as is?

@zgrybus
Copy link

zgrybus commented Nov 25, 2020

Any progress on that?

@turbobeast
Copy link

turbobeast commented Jun 15, 2021

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;
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants