Skip to content

Instantly share code, notes, and snippets.

@qetr1ck-op
Last active January 13, 2016 18:28
Show Gist options
  • Save qetr1ck-op/889e6839453852fe1631 to your computer and use it in GitHub Desktop.
Save qetr1ck-op/889e6839453852fe1631 to your computer and use it in GitHub Desktop.
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
expect(
counter(0, { type: 'INCREMENT' })
).toEqual(1);
expect(
counter(1, { type: 'INCREMENT' })
).toEqual(2);
expect(
counter(2, { type: 'DECREMENT' })
).toEqual(1);
expect(
counter(1, { type: 'INCREMENT' })
).toEqual(0);
expect(
counter(1, { type: 'SOMETHING_ELSE' })
).toEqual(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment