msw

Intercept network requests with MSW v2 to mock REST and GraphQL APIs.

3|1|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/thongdn-it/react-agent-skills --skill msw
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: msw
Source: https://github.com/thongdn-it/react-agent-skills/tree/main/skills/msw
Command: npx skills add https://github.com/thongdn-it/react-agent-skills --skill msw

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

MSW-based API mocking eliminates flaky tests by intercepting network requests and returning deterministic responses.

Core Features & Use Cases

  • Centralized, declarative mocks for HTTP and GraphQL requests with fine-grained control over responses.
  • Cross-environment support for browser and Node.js to simulate real-world API interactions in UI tests and SSR.
  • Seamless integration with common test runners (Jest, Vitest) to model success, errors, delays, and edge cases.

Quick Start

Install MSW and begin by defining request handlers to mock your REST and GraphQL APIs.

Frequently Asked Questions about msw

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

FAQPage Schema
How does API mocking eliminate flaky tests in Node and browser environments?

API mocking intercepts network requests to return deterministic responses, eliminating flaky tests. It supports both browser and Node environments by simulating real-world REST and GraphQL interactions without hitting actual endpoints.

Can I use Mock Service Worker to simulate GraphQL and REST API calls?

Yes, you can use Mock Service Worker to simulate both GraphQL and REST API calls. It provides centralized, declarative mocks with fine-grained control over responses, allowing you to model success, errors, and edge cases seamlessly.

Does API mocking with MSW work with Jest and Vitest test runners?

Yes, MSW API mocking integrates seamlessly with common test runners like Jest and Vitest. This integration allows you to model success, errors, delays, and edge cases directly within your UI and backend test suites.

How do I set up MSW v2 request handlers for HTTP mocking?

To set up MSW v2 for HTTP mocking, define declarative request handlers to intercept network calls. The process enforces strict URL matching and explicit body parsing, utilizing lifecycle events for debugging.

What is the best way to debug intercepted network requests during API mocking?

The best way to debug intercepted network requests is by utilizing MSW lifecycle events. These events provide visibility into request matching and response resolution, ensuring your mocked HTTP and GraphQL calls behave as expected.