diff --git a/src/features/todos/__snapshots__/todosSlice.spec.js.snap b/src/features/todos/__snapshots__/todosSlice.spec.js.snap new file mode 100644 index 0000000..ead51ae --- /dev/null +++ b/src/features/todos/__snapshots__/todosSlice.spec.js.snap @@ -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", + }, +] +`; diff --git a/src/features/todos/todosSlice.spec.js b/src/features/todos/todosSlice.spec.js new file mode 100644 index 0000000..b19c070 --- /dev/null +++ b/src/features/todos/todosSlice.spec.js @@ -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(); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index bcfa6c0..d9f85f3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,7 +23,6 @@ /* allow the incremential inclusion of JavaScript files */ "allowJs": true, - "checkJs": false, "noImplicitAny": true, "baseUrl": ".", diff --git a/vite.config.ts b/vite.config.ts index c34805e..17da149 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -17,7 +17,6 @@ export default defineConfig({ '**/*.{test,spec}.?(c|m)[jt]s?(x)', ], exclude: [ - '**/*.test.js', '**/node_modules/**', '**/dist/**', '**/coverage/**',