Skip to content

Commit cc9f6ba

Browse files
committed
fix doubleAsync() post-immutable
1 parent c6ac3ef commit cc9f6ba

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/redux/modules/counter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const doubleAsync = () => {
2121
return (dispatch, getState) => {
2222
return new Promise((resolve) => {
2323
setTimeout(() => {
24-
dispatch(increment(getState().counter));
24+
dispatch(increment(getState().get('counter')));
2525
resolve();
2626
}, 200);
2727
});

tests/redux/modules/counter.spec.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Map } from 'immutable';
12
import {
23
COUNTER_INCREMENT,
34
increment,
@@ -55,14 +56,14 @@ describe('(Redux Module) Counter', function () {
5556
let _getStateSpy;
5657

5758
beforeEach(function () {
58-
_globalState = {
59+
_globalState = new Map();
60+
_globalState = _globalState.merge({
5961
counter: counterReducer(undefined, {})
60-
};
62+
});
6163
_dispatchSpy = sinon.spy((action) => {
62-
_globalState = {
63-
..._globalState,
64-
counter: counterReducer(_globalState.counter, action)
65-
};
64+
_globalState = _globalState.merge({
65+
counter: counterReducer(_globalState.get('counter'), action)
66+
});
6667
});
6768
_getStateSpy = sinon.spy(() => {
6869
return _globalState;
@@ -90,19 +91,19 @@ describe('(Redux Module) Counter', function () {
9091
});
9192

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

9596
return doubleAsync()(_dispatchSpy, _getStateSpy)
9697
.then(() => {
9798
_dispatchSpy.should.have.been.calledOnce;
9899
_getStateSpy.should.have.been.calledOnce;
99-
expect(_globalState.counter).to.equal(4);
100+
expect(_globalState.get('counter')).to.equal(4);
100101
return doubleAsync()(_dispatchSpy, _getStateSpy);
101102
})
102103
.then(() => {
103104
_dispatchSpy.should.have.been.calledTwice;
104105
_getStateSpy.should.have.been.calledTwice;
105-
expect(_globalState.counter).to.equal(8);
106+
expect(_globalState.get('counter')).to.equal(8);
106107
});
107108
});
108109
});

0 commit comments

Comments
 (0)