Redux
Intermediate
Testing Redux Logic
Learn to test reducers, selectors, and thunks effectively.
25 min
3 sections
testing
vitest
quality
1
2
3
01. Testing Reducers
Section 1 of 3
Reducers are pure functions and easy to test. Call them with initial state and actions, assert on result.
typescript
import todosReducer from './slice';
import { addTodo } from './slice';
describe('todos reducer', () => {
it('handles addTodo', () => {
const initialState = { items: [] };
const action = addTodo({ text: 'Test' });
const state = todosReducer(initialState, action);
expect(state.items).toHaveLength(1);
expect(state.items[0].text).toBe('Test');
});
});Exercise
Test a Reducer
Practice
Write a test for a counter reducer's increment action.
Back to Course