Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Remove unnecessary reducer call (#66)
Browse files Browse the repository at this point in the history
Remove unnecessary reducer call
  • Loading branch information
kevanstannard authored and tptee committed Sep 16, 2016
1 parent aed686c commit b93b5c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/store-enhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default ({
}

return {
...reducer(vanillaState, action),
...newState,
router: routerReducer(state && state.router, action)
};
};
Expand Down
15 changes: 14 additions & 1 deletion test/store-enhancer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ const defaultFakeInitialState = {
}
};

const defaultReducer = store => store;

const fakeStore = ({
initialState = defaultFakeInitialState,
routes = defaultRoutes,
reducer = defaultReducer,
useHistoryStub = true,
isLoop = false,
enhancerOptions = {}
Expand Down Expand Up @@ -72,14 +75,15 @@ const fakeStore = ({
const store = createStore(
isLoop ? combineReducers({
stuff: state => state
}) : state => state,
}) : reducer,
initialState,
compose(...enhancers)
);

return { store, historyStub };
};

// eslint-disable-next-line max-statements
describe('Router store enhancer', () => {
it('throws if no routes are provided', () => {
expect(() => fakeStore({
Expand Down Expand Up @@ -350,4 +354,13 @@ describe('Router store enhancer', () => {
});
expect(store.dispatchSpy).to.be.calledOnce;
});

it('calls the reducer once for each action', () => {
const reducerSpy = sandbox.spy();
const { store } = fakeStore({ reducer: reducerSpy });
store.dispatch({ type: 'CUSTOM_ACTION' });
expect(reducerSpy).to.be.calledTwice;
expect(reducerSpy.firstCall).to.have.been.calledWith({}, { type: '@@redux/INIT' });
expect(reducerSpy.secondCall).to.have.been.calledWith({}, { type: 'CUSTOM_ACTION' });
});
});

0 comments on commit b93b5c3

Please sign in to comment.