Learn how to use Object.assign() and the spread operator proposed for ES7 to avoid mutating objects.
/* * Open the console to see * that the tests have passed. */ const toggleTodo = (todo) => { 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.');
Here '...todo', spread object, whcih is not available in ES6, but will be in ES7, It is fairly popular, and it is enabled in Babel if you use the stage two preset.