Blog

MSW Mock Service Worker: CORS headers in handlers, Jest and Vitest integration, and Node versus browser

MSW intercepts at the network layer—add Access-Control-* in handlers when tests run in jsdom with real fetch.

1 min read
mswtestingcors

GraphQL handlers

GraphQL POST requests still trigger preflight when Content-Type is non-simple—mirror API behavior in tests.

Batching queries changes header signatures—keep CORS tests aligned with Apollo Client settings.

Storybook

Decorators that wrap MSW should not duplicate CORS headers already emitted by the dev server.

Chromatic snapshots cannot capture CORS—document expected headers in story parameters instead.

Back to blog