Unit Testing Patterns
unit-testing
Unit testing patterns: Vitest config with v8 coverage, Testing Library behavior testing, MSW for HTTP mocking (vs jest.mock), it.each parametrized tests, spies vs mocks vs stubs, testing async code, snapshot testing guidelines. Use when writing unit and component tests.
SKILL.md
Full skill instructions
Unit Testing Patterns
When to use
- Setting up Vitest or Jest for a new project
- Writing unit tests for business logic
- Component testing with Testing Library
- Mocking HTTP requests with MSW
- Parametrized tests with it.each
Core principles
- Test behavior, not implementation — what does it return/do, not how
- MSW over jest.mock — mock at network level, not module level
- One assertion per test — single reason to fail per test
- Arrange-Act-Assert — consistent structure in every test
- No test interdependence — each test must run independently
References available
references/vitest-config.md— globals, environment, coverage thresholds, thread pool, MSW setupreferences/business-logic-testing.md— pure function tests, AAA pattern, it.each parametrized testsreferences/msw-http-mocking.md— handlers setup, server lifecycle, per-test handler overridesreferences/async-testing.md— await patterns, rejected promise assertions, try/catch error checksreferences/testing-library-react.md— render, screen queries, userEvent vs fireEvent, role queries
