Last active
June 8, 2017 05:17
-
-
Save TapaniAla/1cf3f126fdbc34bc3c289550cf806715 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/cequnu
This file contains 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 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