msw

Configure MSW v2 API mocking for browser and Node.js tests.

Updated Apr 9, 2026
One-click install
npx skills add https://github.com/remiconnesson/insights-garden --skill msw-remiconnesson
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: msw
Source: https://github.com/remiconnesson/insights-garden/tree/main/.agents/skills/msw
Command: npx skills add https://github.com/remiconnesson/insights-garden --skill msw-remiconnesson

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

This Skill removes the guesswork from configuring MSW so API mocks behave consistently in development and tests. It helps you avoid silent handler mismatches, flaky test isolation problems, and outdated v1 syntax.

Core Features & Use Cases

  • Setup Guidance: Configure the correct browser or Node.js entrypoint, worker or server lifecycle, TypeScript settings, and unhandled-request behavior.
  • Handler Design: Organize request handlers by domain, use proper URL matching, parse request bodies explicitly, and return responses with MSW v2 syntax.
  • Advanced Mocking: Model authentication, cookies, delays, streaming, GraphQL operations, file uploads, passthroughs, and sequential scenarios.
  • Debugging Support: Diagnose interception issues, request mismatches, cache leakage, fake timer conflicts, and concurrent test pollution.
  • Use Case: A team migrating from MSW v1 can use this Skill to refactor handlers, harden tests, and standardize mocking behavior across browser development and Node-based test suites.

Quick Start

Ask for an MSW v2 setup or handler refactor that follows these best practices and applies the right rules to your project.

Frequently Asked Questions about msw

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

FAQPage Schema
How do I set up API mocking for tests and local development with MSW v2?

API mocking with MSW v2 requires configuring the correct browser or Node.js entrypoint, managing the worker or server lifecycle, and setting unhandled-request behavior to ensure consistent interception in development and tests.

Why are my mocked API requests not being intercepted during test runs?

Mocked API requests fail to intercept due to silent handler mismatches, outdated v1 syntax, or cache leakage. Diagnose interception issues by verifying explicit request body parsing and correct MSW v2 URL matching rules.

How do I mock GraphQL operations in MSW v2?

To mock GraphQL operations in MSW v2, organize request handlers by domain and use the proper v2 handler syntax to model GraphQL operations, ensuring explicit request parsing and correct response patterns for your queries and mutations.

Can I use MSW to mock authentication, cookies, and file uploads in a test environment?

Yes, you can use MSW to mock authentication, cookies, delays, streaming, and file uploads. Advanced mocking scenarios also support modeling sequential flows and passthroughs within your isolated test lifecycle management.

What is the best way to isolate API mocks and prevent flaky concurrent test pollution?

The best way to isolate API mocks and prevent flaky concurrent test pollution is to implement isolated test lifecycle management with handler resets and unhandled-request errors, while diagnosing fake timer conflicts and cache leakage.

Does migrating from MSW v1 to v2 require updating request handler syntax?

Migrating from MSW v1 to v2 requires updating request handler syntax, refactoring handlers to use explicit request parsing, and returning responses with the correct MSW v2 syntax to harden tests and standardize mocking behavior.