msw

Configure MSW v2 request handlers for deterministic HTTP and GraphQL mocking.

Updated Mar 11, 2026
One-click install
npx skills add https://github.com/selfagency/agentsy --skill msw-selfagency
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: msw
Source: https://github.com/selfagency/agentsy/tree/main/.agents/skills/msw
Command: npx skills add https://github.com/selfagency/agentsy --skill msw-selfagency

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill prevents broken or flaky API mocking setups by teaching the correct MSW v2 patterns for handler matching, request/response handling, and test isolation so your tests fail loudly instead of silently.

Core Features & Use Cases

  • Reliable MSW v2 handler design: structure handlers, parse request bodies explicitly, and use the correct HttpResponse syntax so mocks behave consistently across environments.
  • Deterministic test behavior: configure server lifecycle hooks, reset handlers between tests, and isolate concurrent tests with server.boundary() to eliminate handler leakage and race conditions.
  • Accurate API simulation: mock real-world REST/GraphQL behavior including query matching, GraphQL operation-based handlers, streaming responses, and correct error semantics.

Quick Start

Tell an AI to generate an MSW v2 server setup and a set of REST and GraphQL request handlers that correctly parse request bodies, match URLs, and enforce strict unhandled-request failures for your test suite.

Frequently Asked Questions about msw

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

FAQPage Schema
How do I prevent flaky mocks in MSW v2 test setups?

Prevent flaky mocks in MSW v2 by structuring request handlers correctly, resetting handlers between tests, and isolating concurrent tests with server.boundary() to eliminate handler leakage and race conditions.

Why does my MSW GraphQL mock not match the correct operation?

MSW GraphQL mocking requires correct resolver destructuring and explicit validation of GraphQL error and operation-name matching behavior to ensure your handlers intercept the intended queries accurately.

How do I parse request bodies correctly when mocking HTTP responses with MSW?

Parse request bodies explicitly in your MSW handlers and use the correct HttpResponse syntax to construct responses, ensuring your HTTP mocks behave consistently across different testing environments.

What's the best way to handle unhandled requests in MSW test isolation?

The best way to handle unhandled requests in MSW test isolation is to enforce strict unhandled-request failures and configure server lifecycle hooks so tests fail loudly instead of silently.

Can I mock streaming responses and REST APIs using MSW v2?

Yes, you can mock streaming responses and simulate real-world REST API behavior using MSW v2 by applying correct handler architecture and response construction patterns for accurate API simulation.

Do I need to configure specific entrypoints for MSW node server setup?

Yes, configuring correct msw/node entrypoints is required for proper server lifecycle management and deterministic test behavior across unit and integration testing workflows.