diff --git a/src/index.js b/src/index.js index 729daf1..bbc5dd9 100644 --- a/src/index.js +++ b/src/index.js @@ -10,7 +10,7 @@ export default (...args) => { } return (prevState, value, ...args) => { - const prevStateIsUndefined = typeof (prevState === 'undefined'); + const prevStateIsUndefined = typeof prevState === 'undefined'; const valueIsUndefined = typeof value === 'undefined'; if (prevStateIsUndefined && valueIsUndefined && initialState) { diff --git a/test/index.test.js b/test/index.test.js index d32e471..b9b470e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -86,3 +86,22 @@ test('no initialState supplied + undefined state: initial state defined by first expect(reducerAB(undefined, 3)).toEqual({ A: 12, B: 2 }); }); + +test('actions should progressively update state', () => { + const reducerA = (state, action) => { + if (action.type === 'A') return { ...state, a: true }; + return state; + }; + const reducerB = (state, action) => { + if (action.type === 'B') return { ...state, b: true }; + return state; + }; + const initial = { a: false, b: false }; + const combined = reduceReducers(reducerA, reducerB, initial); + + let state = combined(undefined, { type: 'A' }); + expect(state).toEqual({ a: true, b: false }); + + state = combined(state, { type: 'B' }); + expect(state).toEqual({ a: true, b: true }); +});