@@ -13,7 +13,7 @@ function createMockTodos() {
1313 { task : "Task 1 description" , completed : true } ,
1414 { task : "Task 2 description" , completed : false } ,
1515 { task : "Task 3 description" , completed : true } ,
16- { task : "Task 4 description" , completed : false } ,
16+ { task : "Task 4 description" , completed : false } ,
1717 ] ;
1818}
1919
@@ -29,7 +29,6 @@ describe("addTask()", () => {
2929 } ) ;
3030
3131 test ( "Should append a new task to the end of a ToDo list" , ( ) => {
32-
3332 const todos = createMockTodos ( ) ;
3433 const lengthBeforeAddition = todos . length ;
3534 Todos . addTask ( todos , theTask . task , theTask . completed ) ;
@@ -42,7 +41,6 @@ describe("addTask()", () => {
4241} ) ;
4342
4443describe ( "deleteTask()" , ( ) => {
45-
4644 test ( "Delete the first task" , ( ) => {
4745 const todos = createMockTodos ( ) ;
4846 const todosBeforeDeletion = createMockTodos ( ) ;
@@ -53,7 +51,7 @@ describe("deleteTask()", () => {
5351
5452 expect ( todos [ 0 ] ) . toEqual ( todosBeforeDeletion [ 1 ] ) ;
5553 expect ( todos [ 1 ] ) . toEqual ( todosBeforeDeletion [ 2 ] ) ;
56- expect ( todos [ 2 ] ) . toEqual ( todosBeforeDeletion [ 3 ] ) ;
54+ expect ( todos [ 2 ] ) . toEqual ( todosBeforeDeletion [ 3 ] ) ;
5755 } ) ;
5856
5957 test ( "Delete the second task (a middle task)" , ( ) => {
@@ -66,7 +64,7 @@ describe("deleteTask()", () => {
6664
6765 expect ( todos [ 0 ] ) . toEqual ( todosBeforeDeletion [ 0 ] ) ;
6866 expect ( todos [ 1 ] ) . toEqual ( todosBeforeDeletion [ 2 ] ) ;
69- expect ( todos [ 2 ] ) . toEqual ( todosBeforeDeletion [ 3 ] ) ;
67+ expect ( todos [ 2 ] ) . toEqual ( todosBeforeDeletion [ 3 ] ) ;
7068 } ) ;
7169
7270 test ( "Delete the last task" , ( ) => {
@@ -79,7 +77,7 @@ describe("deleteTask()", () => {
7977
8078 expect ( todos [ 0 ] ) . toEqual ( todosBeforeDeletion [ 0 ] ) ;
8179 expect ( todos [ 1 ] ) . toEqual ( todosBeforeDeletion [ 1 ] ) ;
82- expect ( todos [ 2 ] ) . toEqual ( todosBeforeDeletion [ 2 ] ) ;
80+ expect ( todos [ 2 ] ) . toEqual ( todosBeforeDeletion [ 2 ] ) ;
8381 } ) ;
8482
8583 test ( "Delete a non-existing task" , ( ) => {
@@ -94,7 +92,6 @@ describe("deleteTask()", () => {
9492} ) ;
9593
9694describe ( "toggleCompletedOnTask()" , ( ) => {
97-
9895 test ( "Expect the 'completed' property to toggle on an existing task" , ( ) => {
9996 const todos = createMockTodos ( ) ;
10097 const taskIndex = 1 ;
@@ -111,13 +108,12 @@ describe("toggleCompletedOnTask()", () => {
111108 const todos = createMockTodos ( ) ;
112109 const todosBeforeToggle = createMockTodos ( ) ;
113110 Todos . toggleCompletedOnTask ( todos , 1 ) ;
114-
115- expect ( todos [ 0 ] ) . toEqual ( todosBeforeToggle [ 0 ] ) ;
111+
112+ expect ( todos [ 0 ] ) . toEqual ( todosBeforeToggle [ 0 ] ) ;
116113 expect ( todos [ 2 ] ) . toEqual ( todosBeforeToggle [ 2 ] ) ;
117114 expect ( todos [ 3 ] ) . toEqual ( todosBeforeToggle [ 3 ] ) ;
118115 } ) ;
119116
120-
121117 test ( "Expect no change when toggling on a non-existing task" , ( ) => {
122118 const todos = createMockTodos ( ) ;
123119 const todosBeforeToggle = createMockTodos ( ) ;
@@ -130,3 +126,19 @@ describe("toggleCompletedOnTask()", () => {
130126 } ) ;
131127} ) ;
132128
129+ // write a Jest test that verifies `deleteCompleted()` works correctly.
130+ describe ( "deleteCompleted()" , ( ) => {
131+ test ( "should delete all the tasks that are marked completed" , ( ) => {
132+ let myTodos = [
133+ { task : "Description of task 1" , completed : false } ,
134+ { task : "Description of task 2" , completed : true } ,
135+ { task : "Description of task 2" , completed : true } ,
136+ ] ;
137+
138+ Todos . deleteCompleted ( myTodos ) ;
139+
140+ expect ( myTodos ) . toEqual ( [
141+ { task : "Description of task 1" , completed : false } ,
142+ ] ) ;
143+ } ) ;
144+ } ) ;
0 commit comments