generated from Uzair-Manzoor/webpack-linters-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test file for clearAllCompleted function
- Loading branch information
1 parent
f3fea4e
commit 454f79b
Showing
1 changed file
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,64 @@ | ||
import 'jest-localstorage-mock'; | ||
import 'jest-localstorage-mock'; | ||
|
||
import clearAllCompletedTasks from '../clearTask.js'; | ||
import { | ||
tasks, | ||
storeTasksToLocalStorage, | ||
deleteTask, | ||
} from '../taskFunctions.js'; | ||
|
||
// Mock the localStorage and DOM elements | ||
jest.mock('../taskFunctions.js', () => ({ | ||
tasks: [ | ||
{ description: 'Task 1', completed: false, index: 1 }, | ||
{ description: 'Task 2', completed: false, index: 2 }, | ||
{ description: 'Task 3', completed: false, index: 3 }, | ||
], | ||
storeTasksToLocalStorage: jest.fn(), | ||
deleteTask: jest.fn(), | ||
addTask: jest.fn(), | ||
sortTasks: jest.fn(), | ||
})); | ||
|
||
const mockDisplayTasks = jest.fn(); | ||
|
||
jest.mock('../../index.js', () => ({ | ||
displayTasks: mockDisplayTasks, | ||
})); | ||
|
||
const emptyTasks = []; | ||
|
||
describe('clearAllCompletedTasks', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should clear all completed tasks', () => { | ||
clearAllCompletedTasks(tasks); | ||
|
||
expect(tasks.length).toBe(3); | ||
expect(tasks[0].description).toBe('Task 1'); | ||
expect(tasks[0].completed).toBe(false); | ||
expect(tasks[1].description).toBe('Task 2'); | ||
expect(tasks[1].completed).toBe(false); | ||
expect(tasks[2].description).toBe('Task 3'); | ||
expect(tasks[2].completed).toBe(false); | ||
expect(storeTasksToLocalStorage).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should not delete not completed tasks', () => { | ||
tasks.forEach((task) => { | ||
task.completed = false; | ||
}); | ||
|
||
clearAllCompletedTasks(tasks); | ||
|
||
expect(deleteTask).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not do anything if the list is empty', () => { | ||
clearAllCompletedTasks(emptyTasks); | ||
|
||
expect(emptyTasks.length).toBe(0); | ||
}); | ||
}); |