msw
3.0.7 · 18 Nov 2026MIT36M / weekRepositoryHomepagenpmAtom feed
0.49.3 is the newest release of 0.21.x.
In short
1 breaking6 new3 fixed2 changed
- Breaking
ctx.fetchutility now returns the entire response, not just the body (#373).
Release note
This release contains changes to the
mockServiceWorker.jsfile. Please follow the instructions in your browser to upgrade the Service Worker file.
Breaking changes
- Breaking
ctx.fetchutility now returns the entire response, not just the body (#373).
- const body = await ctx.fetch(req) + const response = await ctx.fetch(req) + const body = await response.json()
Features
Adds support for mocking any GraphQL operation regardless of its type via
graphql.operationAPI (#343).
import { graphql } from 'msw'
graphql.operation((req, res, ctx) => {
const { query, variables } = req.body
// Execute any GraphQL operation against a mock schema
// and return the response.
return executeSchema(mockSchema, { query, variables })
})import { rest } from 'msw'
interface UserResponseBodyType {
firstName: string
}
rest.get<never, UserResponseBodyType>('/user', (req, res, ctx) => {
return res(ctx.json({ firstName: ‘John’ })
})
interface TodoRequestBodyType {
title: string
}
type TodoResponseBodyType = string[]
rest.post<TodoRequestBodyType, TodoResponseBodyType>('/todo', (req, res, ctx) => {
const { title } = req.body
return res(ctx.json(['one', title]))
})Adds support to
rest.head()request handler to matchHEADmethod requests (#356).Adds
findWorkeroption toworker.start()to locate the mock Service Worker script at a custom location (#335, #351).Adds a keepalive mechanism between a client and the Service Worker to prevent the worker to be terminated due to inactivity (#367, #371).
ctx.jsonnow supports any data types that can be serialized to a valid JSON (#349, #350).
Bug fixes
Fixes an issue that resulted into custom options to
worker.start()not being deeply merged with the default ones (#347, #348).Fixes an issue that resulted into
ctx.json()utility function accepting only objects. Now it accepts any data that can be stringified into JSON (#349, #350).Fixes an issue that resulted into “The “superCtor” argument must be of type function
”error message when usingsetupServer(#49, #50).GET and HEAD requests now forcefully contain no request body (#361, #366).
Internals
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.