Last active
July 2, 2018 00:17
-
-
Save lupomontero/e22cf5e5f75ed1b608f41f6ebded8ed8 to your computer and use it in GitHub Desktop.
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 characters
const reducer = require('./reducer-2'); | |
describe('reducer()', () => { | |
it('should not be affected by previous call', () => { | |
expect(reducer(undefined, { type: 'INCREMENT' })).toEqual({ count: 1 }); | |
expect(reducer(undefined, { type: 'INCREMENT' })).toEqual({ count: 1 }); | |
expect(reducer(undefined, { type: 'DECREMENT' })).toEqual({ count: -1 }); | |
expect(reducer({ count: 99 }, { type: 'INCREMENT' })) | |
.toEqual({ count: 100 }); | |
}); | |
it('should handle increment and decrement actions without mutating state', () => { | |
const state1 = reducer(undefined, { type: 'INCREMENT' }); | |
const state2 = reducer(state1, { type: 'INCREMENT' }); | |
const state3 = reducer(state2, { type: 'DECREMENT' }); | |
expect(state1).toEqual({ count: 1 }); | |
expect(state2).toEqual({ count: 2 }); | |
expect(state3).toEqual({ count: 1 }); | |
expect(state1).not.toBe(state2); | |
expect(state1).not.toBe(state3); | |
expect(state2).not.toBe(state3); | |
}); | |
it('should return the state as it came in when unknown action', () => { | |
const state = { count: 10 }; | |
expect(reducer(state, {})).toBe(state); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment