Skip to content

Commit

Permalink
fix doubleAsync() post-immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
jokeyrhyme committed Feb 23, 2016
1 parent c6ac3ef commit cc9f6ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/redux/modules/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const doubleAsync = () => {
return (dispatch, getState) => {
return new Promise((resolve) => {
setTimeout(() => {
dispatch(increment(getState().counter));
dispatch(increment(getState().get('counter')));
resolve();
}, 200);
});
Expand Down
19 changes: 10 additions & 9 deletions tests/redux/modules/counter.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Map } from 'immutable';
import {
COUNTER_INCREMENT,
increment,
Expand Down Expand Up @@ -55,14 +56,14 @@ describe('(Redux Module) Counter', function () {
let _getStateSpy;

beforeEach(function () {
_globalState = {
_globalState = new Map();
_globalState = _globalState.merge({
counter: counterReducer(undefined, {})
};
});
_dispatchSpy = sinon.spy((action) => {
_globalState = {
..._globalState,
counter: counterReducer(_globalState.counter, action)
};
_globalState = _globalState.merge({
counter: counterReducer(_globalState.get('counter'), action)
});
});
_getStateSpy = sinon.spy(() => {
return _globalState;
Expand Down Expand Up @@ -90,19 +91,19 @@ describe('(Redux Module) Counter', function () {
});

it('Should produce a state that is double the previous state.', function () {
_globalState = { counter: 2 };
_globalState = _globalState.merge({ counter: 2 });

return doubleAsync()(_dispatchSpy, _getStateSpy)
.then(() => {
_dispatchSpy.should.have.been.calledOnce;
_getStateSpy.should.have.been.calledOnce;
expect(_globalState.counter).to.equal(4);
expect(_globalState.get('counter')).to.equal(4);
return doubleAsync()(_dispatchSpy, _getStateSpy);
})
.then(() => {
_dispatchSpy.should.have.been.calledTwice;
_getStateSpy.should.have.been.calledTwice;
expect(_globalState.counter).to.equal(8);
expect(_globalState.get('counter')).to.equal(8);
});
});
});
Expand Down

0 comments on commit cc9f6ba

Please sign in to comment.