Skip to content

Instantly share code, notes, and snippets.

@lupomontero
Last active July 2, 2018 00:14
Show Gist options
  • Save lupomontero/e315116befab50ff0e88c3d736cd353f to your computer and use it in GitHub Desktop.
Save lupomontero/e315116befab50ff0e88c3d736cd353f to your computer and use it in GitHub Desktop.
const reducer = require('./reducer-1');
describe('reducer()', () => {
it('should not be affected by previous calls', () => {
expect(reducer(undefined, { type: 'INCREMENT' })).toEqual({ count: 1 });
expect(reducer(undefined, { type: 'INCREMENT' })).toEqual({ count: 1 });
expect(reducer(undefined, { type: 'DECREMENT' })).toEqual({ count: -1 });
});
it('should handle increment action', () => {
const state1 = reducer(undefined, { type: 'INCREMENT' });
const state2 = reducer(state1, { type: 'INCREMENT' });
// Todas las referencias a state apuntan al mismo objeto que
// hemos ido mutando!!!
expect(state1).toEqual({ count: 2 });
expect(state2).toEqual({ count: 2 });
expect(state1).toBe(state2);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment