Skip to content

Instantly share code, notes, and snippets.

@TapaniAla
Last active June 8, 2017 05:17
Show Gist options
  • Save TapaniAla/1cf3f126fdbc34bc3c289550cf806715 to your computer and use it in GitHub Desktop.
Save TapaniAla/1cf3f126fdbc34bc3c289550cf806715 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/cequnu
const toggleTodo = (todo) => {
// not allowed
//todo.completed = !todo.completed;
//this OK
// return {
// id: todo.id,
// text: todo.text,
// completed: !todo.completed
// };
// note the last assign property wins!
return Object.assign({}, todo, {
completed: !todo.completed
});
//ES7 object spread:
//return {
//...todo,
//completed: !todo.completed
//};
};
const testToggleTodo = () => {
const todoBefore = {
id:0,
text: 'Learn Redux',
completed: false
};
const todoAfter = {
id:0,
text: 'Learn Redux',
completed: true
};
deepFreeze(todoBefore);
expect(
toggleTodo(todoBefore)
).toEqual(todoAfter);
}
testToggleTodo();
console.log('All tests passed');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment