Created
September 4, 2018 11:29
-
-
Save oroce/52c2ac791b79568785283d98f1409db9 to your computer and use it in GitHub Desktop.
Revisions
-
oroce created this gist
Sep 4, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ { "scripts": "mocha -r should '*.spec.js'" } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ export default (action, state = { sum: 0 }) => { switch (action.type) { case 'add': { return { ...state, sum: state.sum + action.payload.num }; }; case 'subtract': { return { ...state, sum: state.sum - action.payload.num }; }; default: { return state; } }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ import reducer from './reducer'; describe('reducer', () => { it('should add the number to the sum', () => { reducer({ type: 'add', payload: { num: 2 } }, { sum: 4 }).should.eql({ sum: 6 }); }); it('should not add fail with no state', () => { reducer({ type: 'add', payload: { num: 2 } }).should.eql({ sum: 2 }); }); it('should subtract the number', () => { reducer({ type: 'subtract', payload: { num: 2 } }, { sum: 4 }).should.eql({ sum: 2 }); }); it('should not subtract fail with no state', () => { reducer({ type: 'subtract', payload: { num: 2 } }).should.eql({ sum: -2 }); }); });