Zum Hauptinhalt springen
MSW (Mock Service Worker) logo

MSW (Mock Service Worker)

Industry standard API mocking for JavaScript

Mock Service Worker (MSW) is an API mocking library for browser and Node.js. It intercepts requests at the network level using Service Workers, enabling the same mock definitions for unit, integration, and E2E testing without modifying application code.

16.0k
GitHub Stars
free
Preise
No
Self-Hostable

Funktionen

  • Service Worker-based interception
  • REST API mocking
  • GraphQL mocking
  • WebSocket mocking
  • Browser and Node.js support
  • Framework agnostic
  • Works with any HTTP client
  • Request observation
  • Type-safe with TypeScript
  • Reusable across test types

Vorteile

  • + Network-level interception
  • + No code changes needed
  • + Reusable mocks across tests
  • + Trusted by Google, Microsoft, Spotify
  • + Great developer experience

Nachteile

  • Service Worker complexity in browsers
  • Setup overhead for simple cases
  • Learning curve for new users
  • Browser Service Worker limitations