msw
MSW (Mock Service Worker) v2 best practices, patterns, and API guidance for API mocking in JavaScript/TypeScript tests and development. Covers handler design, server setup, response construction, testing patterns, GraphQL, and v1-to-v2 migration. Baseline: msw ^2.0.0. Triggers on: msw imports, http.get, http.post, HttpResponse, setupServer, setupWorker, graphql.query, mentions of "msw", "mock service worker", "api mocking", or "msw v2".
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/anivar/msw-skillWhat This Skill Does
The MSW (Mock Service Worker) skill empowers OpenClaw to act as an expert consultant for API mocking in JavaScript and TypeScript environments. It is specifically calibrated for MSW v2, ensuring that all guidance—from architecture patterns to syntax—adheres to current best practices. This skill helps you navigate the significant breaking changes from v1, such as the total removal of the rest namespace and the transition to the HttpResponse and http handler structure. By using this skill, you avoid outdated patterns like (req, res, ctx) resolvers and ensure your network-level mocking is robust, scalable, and type-safe.
Installation
To install this skill, run the following command in your terminal:
clawhub install openclaw/skills/skills/anivar/msw-skill
Use Cases
MSW is the industry standard for intercepting network requests in testing and development without modifying application source code. Use this skill when you need to:
- Set up comprehensive test suites for React, Vue, or Node.js applications using
setupServerfor test isolation. - Create a development server using
setupWorkerto simulate backends during frontend-only development. - Debug failing tests caused by incorrect handler definitions or deprecated syntax.
- Implement complex response logic using
HttpResponse,delay, andpassthroughto simulate network conditions like high latency or server errors. - Migrate an existing codebase from MSW v1 to v2 safely by identifying legacy patterns and replacing them with modern v2 alternatives.
Example Prompts
- "How do I rewrite this v1 mock handler that uses
res(ctx.json({ data: 'old' }))to use the MSW v2HttpResponsepattern?" - "Can you help me set up a
setupServerinstance in Vitest that resets handlers after every test to prevent cross-test state pollution?" - "My MSW handler for
/api/v1/search?query=testis not catching requests. How should I handle query parameters in MSW v2?"
Tips & Limitations
- Rule of Truth: Always trust the official MSW v2 documentation and your project's code over older community blog posts or outdated StackOverflow answers.
- Network Level: Remember that MSW intercepts requests at the network level. If your code uses a hardcoded
fetchthat bypasses the browser's global scope, check your polyfills. - Scope: This skill does not replace integration testing. While MSW is excellent for mocking, always complement it with E2E tests using tools like Playwright to verify that your mocks haven't drifted from actual backend implementations.
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-anivar-msw-skill": {
"enabled": true,
"auto_update": true
}
}
}Tags(AI)
Related Skills
zod-testing
Testing patterns for Zod schemas using Jest and Vitest. Covers schema correctness testing, mock data generation, error assertion patterns, integration testing with API handlers and forms, snapshot testing with z.toJSONSchema(), and property-based testing. Baseline: zod ^4.0.0. Triggers on: test files for Zod schemas, zod-schema-faker imports, mentions of "test schema", "schema test", "zod mock", "zod test", or schema testing patterns.
jest
Jest best practices, patterns, and API guidance for JavaScript/TypeScript testing. Covers mock design, async testing, matchers, timer mocks, snapshots, module mocking, configuration, and CI optimization. Baseline: jest ^29.0.0 / ^30.0.0. Triggers on: jest imports, describe, it, test, expect, jest.fn, jest.mock, jest.spyOn, mentions of "jest", "unit test", "test suite", or "mock".
redux-saga-testing
Write tests for Redux Sagas using redux-saga-test-plan, runSaga, and manual generator testing. Covers expectSaga (integration), testSaga (unit), providers, partial matchers, reducer integration, error simulation, and cancellation testing. Works with Jest and Vitest. Triggers on: test files for sagas, redux-saga-test-plan imports, mentions of "test saga", "saga test", "expectSaga", "testSaga", or "redux-saga-test-plan".
zod
Zod v4 best practices, patterns, and API guidance for schema validation, parsing, error handling, and type inference in TypeScript applications. Covers safeParse, object composition, refinements, transforms, codecs, branded types, and v3→v4 migration. Baseline: zod ^4.0.0. Triggers on: zod imports, z.object, z.string, z.infer, safeParse, mentions of "zod", "schema validation", "zod v4", or "z.enum".
redux-saga
Redux-Saga best practices, patterns, and API guidance for building, testing, and debugging generator-based side-effect middleware in Redux applications. Covers effect creators, fork model, channels, testing with redux-saga-test-plan, concurrency, cancellation, and modern Redux Toolkit integration. Baseline: redux-saga 1.4.2. Triggers on: saga files, redux-saga imports, generator-based middleware, mentions of "saga", "takeEvery", "takeLatest", "fork model", or "channels".