auto-generated-test-setup-with-msw

Automate MSW-based API mocking setup for Vitest tests.

Updated Aug 17, 2025
One-click install
npx skills add https://github.com/planetaryescape/ai-digest --skill auto-generated-test-setup-with-msw
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: auto-generated-test-setup-with-msw
Source: https://github.com/planetaryescape/ai-digest/tree/main/.claude/skills/auto-generated-test-setup-with-msw
Command: npx skills add https://github.com/planetaryescape/ai-digest --skill auto-generated-test-setup-with-msw

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a reliable test setup that uses MSW (Mock Service Worker) to mock external APIs for Vitest tests, ensuring deterministic and fast test runs.

Core Features & Use Cases

  • Global MSW server setup in test/setup.ts and handlers in test/mocks/handlers.ts
  • MSW v2 HTTP handler patterns for realistic mock responses
  • Environment variable mocking and test configuration for CI consistency
  • Enforced unhandled request errors to prevent silent failures
  • Detailed coverage thresholds to guard test quality

Quick Start

Install dependencies and run the MSW-enabled Vitest test suite to verify the mocked HTTP handlers.

Frequently Asked Questions about auto-generated-test-setup-with-msw

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up MSW for mocking API calls in Vitest?

Set up MSW for mocking API calls in Vitest by configuring a global MSW server in your test setup file and defining HTTP handlers to intercept and mock external network requests for deterministic test runs.

What is the best way to catch unhandled HTTP requests during Vitest test runs?

The best way to catch unhandled HTTP requests in Vitest is to enforce unhandled request errors within your MSW server configuration, preventing silent test failures and ensuring all external API calls are explicitly mocked.

Can I mock environment variables alongside HTTP requests in Vitest?

Yes, you can mock environment variables alongside HTTP requests in Vitest. This combined setup ensures CI consistency by isolating test environments from external configuration and network dependencies.

How do I configure MSW v2 HTTP handler patterns for realistic mock API responses?

Configure MSW v2 HTTP handler patterns by defining request interceptors in your handlers file that return realistic mock responses, allowing your Vitest test suite to accurately simulate external API behaviors.

Why does my Vitest test suite need coverage thresholds with API mocking?

Vitest test suites need coverage thresholds with API mocking to guard test quality. Combining deterministic mocked HTTP responses with enforced coverage metrics ensures robust validation across development and CI environments.