-
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.
feat(todos): updated to run javascript unit tests, added reducer unit…
… tests
- Loading branch information
Showing
4 changed files
with
63 additions
and
2 deletions.
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`todos reducer > should handle initial state 1`] = ` | ||
[ | ||
{ | ||
"completed": false, | ||
"id": 1708982768968, | ||
"text": "Hit the gym", | ||
}, | ||
{ | ||
"completed": true, | ||
"id": 1708982943626, | ||
"text": "Meet George", | ||
}, | ||
] | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-env jest */ | ||
import { vi } from 'vitest'; | ||
import todosReducer, { addTodo, deleteTodo, editTodo, toggleComplete } from './todosSlice'; | ||
|
||
describe('todos reducer', () => { | ||
let initialState; | ||
let date; | ||
|
||
beforeEach(() => { | ||
initialState = [ | ||
{ id: 1708982768968, text: 'Hit the gym', completed: false }, | ||
{ id: 1708982943626, text: 'Meet George', completed: true } | ||
]; | ||
date = new Date(2022, 2, 22); | ||
|
||
vi.useFakeTimers(); | ||
vi.setSystemTime(date); | ||
}); | ||
afterEach(() => { | ||
vi.useRealTimers(); | ||
}); | ||
|
||
test('should handle initial state', () => { | ||
expect(todosReducer(undefined, { type: 'unknown' })).toMatchSnapshot(); | ||
}); | ||
|
||
test('should handle addTodo', () => { | ||
const actual = todosReducer(initialState, addTodo('Newly added item message')); | ||
expect(actual[2].text).toEqual('Newly added item message'); | ||
}); | ||
|
||
test('should handle deleteTodo', () => { | ||
const actual = todosReducer(initialState, deleteTodo(1708982768968)); | ||
expect(actual.length).toEqual(1); | ||
expect(actual[0].text).toBe('Meet George'); | ||
}); | ||
|
||
test('should handle editTodo', () => { | ||
const actual = todosReducer(initialState, editTodo({id: 1708982768968, text: 'Hit the library'})); | ||
expect(actual[0].text).toBe('Hit the library'); | ||
}); | ||
|
||
test('should handle toggleComplete', () => { | ||
const actual = todosReducer(initialState, toggleComplete(1708982768968)); | ||
expect(actual[0].completed).toBeTruthy(); | ||
}); | ||
}); |
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
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