Toggle a Todo Between Completed and Not Completed
Story: As a user, I want to be able to toggle a todo between completed and not completed statuses, so that I can keep track of it.
TodoMVC actions
It should create an action to toggle a todo between completed and not completed
Write a test.
diff --git a/tests/todomvc/actions.spec.js b/tests/todomvc/actions.spec.js
index fd31f8f..367d6ad 100644
--- a/tests/todomvc/actions.spec.js
+++ b/tests/todomvc/actions.spec.js
@@ -29,5 +29,13 @@ describe('TodoMVC actions', () => {
};
expect(todomvc.actions.deleteTodo('my_id')).to.deep.equal(expectedAction)
+ });
+
+ it('Should create an action to toggle a todo between completed and not completed', () => {
+ const expectedAction = {
+ type: todomvc.types.TOGGLE_COMPLETE_ONE, id: 'my_id'
+ };
+
+ expect(todomvc.actions.toggleCompleteOneTodo('my_id')).to.deep.equal(expectedAction)
})
});
(END)Run the test and watch it fail.
Write the code to make the test pass.
Run the test and watch it pass.
Commit changes.
TodoMVC reducer
It should handle TOGGLE_COMPLETE_ONE todo
Write the test.
Run the test and watch it fail.
Write the code to make the test pass.
Run the test and watch it pass.
Commit changes.
TodoItem component
It Should render correctly
It should have a toggle complete status checkbox
Write the test.
Run the test and watch it fail.
Write the code to make the test pass.
Run the test and watch it pass.
Commit changes.
It should behave correctly
It should call toggleCompleteOneTodo() when the complete status checkbox is changed
Write the test.
Run the test and watch it fail.
Write the code to make the test pass, but also let's immediately work on the required prop warning regression.
Run the test and watch it pass.
Commit changes.
Run It!
Now let's see what this looks like.
Open http://localhost:4000 in your web browser.
Type "Hello" into the text input box and see a new complete status checkbox appear.

Last updated
Was this helpful?