Skip to content

Instantly share code, notes, and snippets.

@TapaniAla
Last active June 1, 2017 08:19
Show Gist options
  • Save TapaniAla/c9d247edd7944ead372dea26ee30177e to your computer and use it in GitHub Desktop.
Save TapaniAla/c9d247edd7944ead372dea26ee30177e to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/cequnu
const todos = (state=[], action) => {
switch (action.type) {
case 'ADD_TODO':
return [
...state,
{id: action.id,
text: action.text,
completed: false
}
];
default:
return state;
}
};
const testAddTodo = () => {
const stateBefore = [];
const action = {
type: 'ADD_TODO',
id: 0,
text: 'Learn Redux'
};
const stateAfter = [
{
id: 0,
text: 'Learn Redux',
completed: false
}
];
deepFreeze(stateBefore);
deepFreeze(action);
expect(
todos(stateBefore, action)
).toEqual(stateAfter);
};
testAddTodo();
console.log('Tests passed');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment