Delete a Todo
Story: As a user, I want to delete a todo from my todos list.
TodoMVC actions
It should create an action to delete a todo
Write a test.
diff --git a/tests/todomvc/actions.spec.js b/tests/todomvc/actions.spec.js
index 694dd04..fd31f8f 100644
--- a/tests/todomvc/actions.spec.js
+++ b/tests/todomvc/actions.spec.js
@@ -21,5 +21,13 @@ describe('TodoMVC actions', () => {
};
expect(todomvc.actions.editTodo('my_id', description)).to.deep.equal(expectedAction)
+ });
+
+ it('Should create an action to delete a todo', () => {
+ const expectedAction = {
+ type: todomvc.types.DELETE, id: 'my_id'
+ };
+
+ expect(todomvc.actions.deleteTodo('my_id')).to.deep.equal(expectedAction)
})
});
(END)Run the test and watch it fail.
Write the code to make the test pass. This time we will define the DELETE action type and use it in the same code change.
Run the test and watch it pass.
Commit changes.
TodoMVC reducer
It should handle DELETE 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 delete button
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
Should call deleteTodo() when the delete button is clicked
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.
Let's now fix the required prop warning regression in the same way we did it for editTodo action.
Run the test and watch it pass, this time without the warning.
Commit changes.
Should call deleteTodo() when TodoTextInput onSave is called with no text
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, this time without the warning.
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 delete button appear. Then enter "World". Now click on the "delete todo" button next to the "World" todo.

Now doubleclick on "Hello", delete all of the text, hit "enter" button and see that todo being deleted too.
Last updated
Was this helpful?