microsoft / redux-dynamic-modules

Modularize Redux by dynamically loading reducers and middlewares.
https://redux-dynamic-modules.js.org
MIT License
1.07k stars 116 forks source link

Multiple reducer default state throws error #81

Closed breeny closed 5 years ago

breeny commented 5 years ago

Version: 3.5.1

Behaviour: If I have multiple modules, with multiple reducers loading on the initial createStore call, the reducer values are ignored. This creates issues when unit testing connected components as re-renders aren't being captured when asserting behaviour.

Expected: I should be able to declare an initial state for multiple reducers

e.g.

//createStore.js

createStore(
  initialState,
  [applyMiddleware(analyticsMiddleware)],
  [getThunkExtension()],
  getUserDataStoreModule(), // creates reducer UserDataStore
  getAnalyticsModule(), // creates reducer Analytics
  getSubmissionModule() //creates reducer SubmissionStore
);

//app.js
createStore({
  UserDataStore: { a: 1, b: 2 },
  Analytics: { a: 1, b: 2 },
  Submission: { a: 1, b: 2 }
});

Throws error in redux.js: Unexpected keys "Analytics", "SubmissionStore" found in previous state received by the reducer. Expected to find one of the known reducer keys instead: "UserDataStore". Unexpected keys will be ignored.

As this is occurring in my unit test environment in a beforeEach hook, the second unit test also throws an error, this time: Unexpected key "SubmissionStore" found in previous state received by the reducer. Expected to find one of the known reducer keys instead: "UserDataStore", "Analytics". Unexpected keys will be ignored.

Current workaround is to lock version at 3.5.0.

abettadapur commented 5 years ago

Thanks for reporting, I will dig into this now