@@ -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" , ( ) => {
@@ -92,9 +90,18 @@ describe("deleteTask()", () => {
9290 expect ( todos ) . toEqual ( todosBeforeDeletion ) ;
9391 } ) ;
9492} ) ;
93+ test ( "Should delete all completed tasks" , ( ) => {
94+ const todos = createMockTodos ( ) ;
95+ const incompleteTasks = Todos . deleteCompleted ( todos ) ;
96+ expect ( incompleteTasks . length ) . toBe ( 2 ) ;
97+ incompleteTasks . forEach ( ( incompleteTask ) => {
98+ expect ( incompleteTask . completed ) . toBe ( false ) ;
99+ } ) ;
100+ expect ( incompleteTasks [ 0 ] . task ) . toBe ( "Task 2 description" ) ;
101+ expect ( incompleteTasks [ 1 ] . task ) . toBe ( "Task 4 description" ) ;
102+ } ) ;
95103
96104describe ( "toggleCompletedOnTask()" , ( ) => {
97-
98105 test ( "Expect the 'completed' property to toggle on an existing task" , ( ) => {
99106 const todos = createMockTodos ( ) ;
100107 const taskIndex = 1 ;
@@ -111,13 +118,12 @@ describe("toggleCompletedOnTask()", () => {
111118 const todos = createMockTodos ( ) ;
112119 const todosBeforeToggle = createMockTodos ( ) ;
113120 Todos . toggleCompletedOnTask ( todos , 1 ) ;
114-
115- expect ( todos [ 0 ] ) . toEqual ( todosBeforeToggle [ 0 ] ) ;
121+
122+ expect ( todos [ 0 ] ) . toEqual ( todosBeforeToggle [ 0 ] ) ;
116123 expect ( todos [ 2 ] ) . toEqual ( todosBeforeToggle [ 2 ] ) ;
117124 expect ( todos [ 3 ] ) . toEqual ( todosBeforeToggle [ 3 ] ) ;
118125 } ) ;
119126
120-
121127 test ( "Expect no change when toggling on a non-existing task" , ( ) => {
122128 const todos = createMockTodos ( ) ;
123129 const todosBeforeToggle = createMockTodos ( ) ;
@@ -129,4 +135,3 @@ describe("toggleCompletedOnTask()", () => {
129135 expect ( todos ) . toEqual ( todosBeforeToggle ) ;
130136 } ) ;
131137} ) ;
132-
0 commit comments