Skip to content

Commit

Permalink
Failing test for nested dispatches
Browse files Browse the repository at this point in the history
  • Loading branch information
leoasis committed Jun 16, 2015
1 parent 2067d5c commit e23b56b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/createRedux.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,29 @@ describe('createRedux', () => {

expect(state).toEqual(redux.getState().todoStore);
});

it('should handle nested dispatches gracefully', () => {
function foo(state = 0, action) {
return action.type === 'foo' ? 1 : state;
}

function bar(state = 0, action) {
return action.type === 'bar' ? 2 : state;
}

const redux = createRedux({ foo, bar });

redux.subscribe(() => {
// What the Connector ends up doing.
const state = redux.getState();
if (state.foo !== 0) {
redux.dispatch({type: 'bar'});
}
});

redux.dispatch({type: 'foo'});

// Either this or throw an error when nesting dispatchers
expect(redux.getState()).toEqual({foo: 1, bar: 2});
});
});

0 comments on commit e23b56b

Please sign in to comment.