Skip to content

Commit

Permalink
Fix typeof call to return a proper value
Browse files Browse the repository at this point in the history
  • Loading branch information
danawoodman authored and timche committed Jul 20, 2018
1 parent 2ab6068 commit 3d5f1ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});

0 comments on commit 3d5f1ce

Please sign in to comment.