msw
MSW (Mock Service Worker)
The API lives in the docs, not here. mswjs.io/docs: intercepting requests, mocking responses, browser and node integration, msw init, structuring handlers, runtime overrides, WebSockets, debugging runbook. There is no llms.txt.
This skill carries what those pages do not: where the Svelte and Storybook toolchain contradicts them, and the traps written down nowhere.
Which seam: vi.mock replaces a module, MSW replaces the network. MSW is svelte-5:testing-svelte's "only mock external services" applied to HTTP, so keep the real component, the real fetch, real Request/Response.
Three surfaces, three handler sets
| Surface | Started in | Handler set |
|---|---|---|
| Storybook | mswLoader() in .storybook/preview.ts |
full: every story must be hermetic |
| Vitest browser | setupWorker in a setup file |
narrow: per-test worker.use() |
| Dev app | gated entry import (hooks.client.ts on SvelteKit) |
narrow: only what the backend lacks |
One shared array across all three means dev stops talking to your backend the moment someone adds a catch-all for a story. The rest, including the catch-all failure signature and stateful factories, is in references/handlers.md.
The worker script comes from msw init <dir> --save, into public/ on Vite and static/ on SvelteKit, and Storybook must serve it via staticDirs. When every story fails at once rather than one of them, suspect the worker before the handlers: open /mockServiceWorker.js in the browser, and a 404 or a MIME-type error there means it is not being served (browser integration).