Maintenance in progress: we are indexing a large batch of new skills. Some pages may load slowly or briefly show no results. Nothing is lost, and everything is back to normal within the hour.

Msw

Mock Service Worker API mocking, request handlers, and integration testing.

majiayu000 fb0cca8 2 files · 2.1 KB Updated 567 repo stars

File contents

MSW Skill

Expert assistance for API mocking with Mock Service Worker.

Capabilities

  • Create request handlers
  • Mock REST and GraphQL APIs
  • Handle network errors
  • Integrate with tests
  • Use in development

Handlers

import { http, HttpResponse } from 'msw';

export const handlers = [
  http.get('/api/users', () => {
    return HttpResponse.json([
      { id: '1', name: 'John' },
      { id: '2', name: 'Jane' },
    ]);
  }),

  http.post('/api/users', async ({ request }) => {
    const body = await request.json();
    return HttpResponse.json({ id: '3', ...body }, { status: 201 });
  }),

  http.get('/api/users/:id', ({ params }) => {
    return HttpResponse.json({ id: params.id, name: 'John' });
  }),
];

Test Integration

import { setupServer } from 'msw/node';
import { handlers } from './handlers';

const server = setupServer(...handlers);

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

Target Processes

  • api-mocking
  • integration-testing
  • frontend-development

majiayu000/claude-skill-registry-data/tree/main/testing/msw-a5c-ai-babysitter commit fb0cca80bb

Frequently asked questions

npx skillmds add majiayu000/msw-2