Unit Testing Patterns

VerifiedSafe

This skill covers unit testing patterns including Vitest configuration with v8 coverage, Testing Library for component behavior, MSW for HTTP mocking, parametrized tests with it.each, and guidelines for spies/mocks/stubs. Use it to set up and write unit/component tests with a focus on testing behavior over implementation.

Sby Skills Guide Bot
TestingIntermediate
306/2/2026
Claude Code
#unit-testing#vitest#testing-library#msw#parametrized-tests

Recommended for

Our review

Provides patterns for unit testing including Vitest configuration, Testing Library component testing, MSW for HTTP mocking, parametrized tests, and async testing.

Strengths

  • Emphasizes testing behavior over implementation
  • Recommends MSW over jest.mock for network level mocking
  • Provides ready-to-use references for common testing scenarios
  • Covers both business logic and UI component testing

Limitations

  • Assumes familiarity with basic testing concepts
  • Examples may not cover every edge case
  • Limited to JavaScript/TypeScript ecosystem
When to use it

Use when setting up a new testing infrastructure or writing unit/component tests for a JavaScript/TypeScript project.

When not to use it

Do not use for end-to-end testing or integration tests that require full system interaction.

Security analysis

Safe
Quality score90/100

The skill defines unit testing patterns and only uses read-only tools (Read, Grep, Glob). There are no destructive actions, code execution, or data exfiltration.

No concerns found

Examples

Set up Vitest with coverage
Set up Vitest with v8 coverage for my React project.
Write parametrized tests for a pure function
Write a unit test for a pure function that calculates discounts using parametrized tests.
Mock HTTP request with MSW for component test
Mock an HTTP GET request using MSW for a component test.

name: unit-testing description: | 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. allowed-tools: Read, Grep, Glob

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

  1. Test behavior, not implementation — what does it return/do, not how
  2. MSW over jest.mock — mock at network level, not module level
  3. One assertion per test — single reason to fail per test
  4. Arrange-Act-Assert — consistent structure in every test
  5. No test interdependence — each test must run independently

References available

  • references/vitest-config.md — globals, environment, coverage thresholds, thread pool, MSW setup
  • references/business-logic-testing.md — pure function tests, AAA pattern, it.each parametrized tests
  • references/msw-http-mocking.md — handlers setup, server lifecycle, per-test handler overrides
  • references/async-testing.md — await patterns, rejected promise assertions, try/catch error checks
  • references/testing-library-react.md — render, screen queries, userEvent vs fireEvent, role queries
Related skills