NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #2889 most downloaded on npm
Seamless REST/GraphQL API mocking library for browser and Node.js.
Last release 2 months ago
08 Jul 2026
Release timing varies
gaps range from 8 days to 2 months
Nearly every release is documented
notes for 60 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
8 years old
337 releases · first in 2018
Fixes type annotations of ResponseTransformer to drop the usage of the unknown generics causing type violations in strict mode (#381, #382).
ResponseTransformer to drop the usage of the unknown generics causing type violations in strict mode (#381, #382).Fixes an issue that resulted into TypeScript violations in strict mode (#377, #379).
One column per quarter.
> This release contains changes to the mockServiceWorker.js file. Please follow the instructions in your browser to upgrade the Service Worker file.
This release contains changes to the
mockServiceWorker.jsfile. Please follow the instructions in your browser to upgrade the Service Worker file.
ctx.fetch utility 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()
graphql.operation API (#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 })
})
rest.* request handlers (#345, #352).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]))
})
rest.head() request handler to match HEAD method requests (#356).findWorker option to worker.start() to locate the mock Service Worker script at a custom location (#335, #351).ctx.json now supports any data types that can be serialized to a valid JSON (#349, #350).worker.start() not being deeply merged with the default ones (#347, #348).ctx.json() utility function accepting only objects. Now it accepts any data that can be stringified into JSON (#349, #350).setupServer (https://github.com/mswjs/node-request-interceptor/issues/49, https://github.com/mswjs/node-request-interceptor/pull/50).Fixes an issue that resulted into a Export has or is using name 'ParsedRestRequest' from external module error message when compiling a TypeScript pro
Export has or is using name 'ParsedRestRequest' from external module error message when compiling a TypeScript project using MSW (#325, #333).node-request-interceptor to version 0.3.5 (see Changelog).Fixes an issue that produces a "Must provide source" error during GraphQL parsing of POST requests with body, but without the query property (#234, #3
query property (#234, #328, #329).http module being patched in React Native environment, where it's not present (#203, #331).node-request-interceptor@0.3.4 (#331)Fixes an issue that resulted into the first matching request handler being treated as the only relevant request handler, even if it doesn't return any
Adds graphql.link request handler that allows to mock GraphQL operations on per-endpoint basis (#315, #319).
graphql.link request handler that allows to mock GraphQL operations on per-endpoint basis (#315, #319).import { setupWorker, graphql } from 'msw'
const github = graphql.link('https://api.github.com/graphql')
const stripe = graphql.link('https://api.stripe.com/graphql')
const worker = setupWorker(
github.query('GetUser', resolver),
stripe.mutation('Payment', resolver),
)
worker.start()
ERROR in node_modules/msw/lib/types/context/cookie.d.ts:1:8 - error TS1192:
Module '"/node_modules/@types/cookie/index"' has no default export.
Fixes an issue with the node-fetch dependency that wasn't listed as a save dependency
node-fetch dependency that wasn't listed as a save dependency (#308)/native not being published to NPM (#309)composeMocks function has been removed (#236, #239). Please use setupWorker instead. ```diff -import { composeMocks, rest } from 'msw' -composeMocks(r
composeMocks function has been removed (#236, #239). Please use setupWorker instead.-import { composeMocks, rest } from 'msw'
-composeMocks(rest.get(...))
+import { setupWorker, rest } from 'msw'
+setupWorker(rest.get(...))
import { setupServer } from 'msw/native'
import { rest } from 'msw'
const server = setupServer(
rest.get('/user', (req, res, ctx) => {
return res(ctx.json({ firstName: 'John' })
})
)
The
setupServerAPI for React Native is the exact mirror of the same API for NodeJS. Read more in the documentation: https://mswjs.io/docs/api/setup-server
setupWorker docs, setupServer docs).const server = setupServer(
rest.get('/books', (req, res, ctx) => res())
)
server.listen({
onUnhandledRequest: 'error'
})
fetch('/user') // ERROR! Unhandled request.
req.cookies property to access a request’s cookies (#199, #261, Accessing request cookies recipe).res.networkError API):rest.post('/login', (req, res, ctx) => {
return res.networkError('Custom error message')
})
worker.start() or Hot Reload (#244).XMLHttpRequest.prototype.addEventListener events being ignored (#267).req.body in case of GraphQL request (#297, #302).Adds a warning when using redundant query parameters in a request handler URL (#231, #233).
setupWorker in a NodeJS environment (#219).setupServer in a browser environment (#214, #219).worker.start() and the worker script doesn’t exist (#237, #242).GraphQLMockedRequest, GraphQLMockedContext, GraphQLRequestPayload, GraphQLResponseResolver types (#213, #241).ctx.delay() to 5ms when run in Node environment (including jsdom) (#205).jest.useFakeTimers() in your tests (#243).Updates the repository's homepage and README.
Fixes an issue that resulted into GraphQL requests issued using a GET method not being intercepted (#210, #212).
GET method not being intercepted (#210, #212).Fixes an issue that resulted into TypeError [ERR_INVALID_URL]: Invalid URL: undefined//undefined exception when using third-party request issuing libr
TypeError [ERR_INVALID_URL]: Invalid URL: undefined//undefined exception when using third-party request issuing libraries in Node (#209, #211).Calling ctx.delay() without any arguments now simulates a random realistic server response time in a range between 100-400ms (#192, #198). Responses i
ctx.delay() without any arguments now simulates a random realistic server response time in a range between 100-400ms (#192, #198). Responses in Node are instantaneous.Uncaught (in promise) SyntaxError: Unexpected end of input exception when processing a request. Internally, a request’s body is now always retrieved as text, parsing it as JSON is delegated to the client side (based on the Content-Type header) (#200, #201).The library now defers all the client-side requests that happen between calling worker.start() and successful worker activation. This eliminates race
worker.start() and successful worker activation. This eliminates race condition between the two, and now comes as the default behavior. (#190, #196)The behavior of deferring requests can be configured using the waitUntilReady: boolean option on worker.start():
import { setupWorker, rest } from 'msw'
const worker = setupWorker(/* request handlers */)
worker.start({
// You can opt-out of the deferred network requests behavior.
waitUntilReady: false
})
Fixes an outdated repository URL in the Service Worker activation message.
ReferenceError: location is not defined error when using a request handler with a relative URL in setupServer (#193)Adds support for declaring runtime request handlers (#128, #187):
.use() to prepend any request handlers. Any prepended request handlers take priority over existing ones, if their predicate match.
.restoreHandlers() to mark any used one-time request handlers as unused, allowing them to affect network again.
.resetHandlers() to remove any request handlers added on runtime. Optionally accepts a list of next request handlers that replace the initial handlers passed to setupServer/setupWorker call.
res.once(). Such handles will respond with a given mocked response only once upon request match:rest.get('/books', (req, res, ctx) => {
return res.once(ctx.json([1, 2, 3]))
})
msw (#185, #186 ):TS7016: Could not find a declaration file for module 'cookie'
mockServiceWorker.js file.Fixes an issue that caused an empty non-JSON request body being parsed as JSON (#175, #179)
Fixes an issue that resulted into responses to axios requests not being mocked properly (#180, #181).
axios requests not being mocked properly (#180, #181).node-request-interceptor as an external dependency of the msw/node bundle.Custom request handlers have reworked lifecycle and accept new methods:
parse(), to retrieve additional information about the request before the predicate.getPublicRequest(), to modify the original request with public information (i.e. adding req.params or req.variables).GraphQL requests are now being printed into browser’s console using a proper format (operation name / response status) (#161, #174)
log function that controls what and how gets printed into browser’s console for introspection:// my-handler.js
export const myHandler = () => {
return {
log(req, res, handler) {
console.log('%s %s', req.method, req.url.href)
}
}
}
The information available in the log function:
req, intercepted request instance;res, resolved mocked response object;handler, exact request handler that captured this request.Content-Type: application/json to be unparsed in req.body reference of the request handler (#171, #172).Fixes an issue that resulted into a relative request's URL being printed as absolute in the browser's console (#164, #167).
> This release introduces bug fixes to the Service Worker file. Please follow the update instructions in your browser's console. Thanks.
This release introduces bug fixes to the Service Worker file. Please follow the update instructions in your browser's console. Thanks.
req.url reference in request handlers is now a URL instance (#158):rest.get('/user', (req) => {
- req.url // "/user"
+ req.url.href // "/user"
})
// test/LoginForm.test.js
import { rest } from 'msw'
import { setupServer } from 'msw/node'
describe('LoginForm', () => {
const server = setupServer(
rest.post('/login', (req, res, ctx) => {
return res(ctx.json({ success: true }))
})
)
beforeAll(() => {
server.listen()
})
afterAll(() => {
server.close()
})
it('allows a user to log in', () => {
// your assertions here...
})
})
req.headers (#154)> This release contains changes to mockServiceWorker.js file. Please follow the instructions in your browser's console to update the worker file.
This release contains changes to
mockServiceWorker.jsfile. Please follow the instructions in your browser's console to update the worker file.
ctx.fetch() (#150, #151):Failed to execute 'text' on 'Response': body stream is locked
mockServiceWorker.js file relatively to the path, instead of the root (#152, #153).Fixed an issue that resulted into request headers not being propagated to an actual request when calling ctx.fetch() to perform response patching (#14
ctx.fetch() to perform response patching (#145, #149).Fixes an issue that resulted into the library's bundle not being tree-shakable (#110, #138)
Fixes an issue that resulted into no request parameters being returned when matched against a URL with query parameters (#130, #141).
SyntaxError: Invalid regular expression: invalid group specifier name exception in Safari and Firefox due to the usage of a negative lookbehind token in RegExp internally (#142, #143)> This release introduces change to the service worker file. Please follow the instructions in your browser's console to update the worker file in you
This release introduces change to the service worker file. Please follow the instructions in your browser's console to update the worker file in your project. Thank you.
ctx.delay() not delaying the mocked response (#136, 137)Fixes an issue that resulted into npx msw init command throwing an error upon successful copying of the worker file (#132, #133)
npx msw init command throwing an error upon successful copying of the worker file (#132, #133)Fixes an issue that resulted into infinite page loading when refreshing a page with "Update on reload" Service Worker option set in Chrome (#119, #129
npx msw init command (#130, #131)Nothing published for this version
Fixes an issue where hard reload of a page with multiple pages controlled by MSW were opened resulted into mocking not working (#122, #126)
The usage of composeMocks() function is deprecated. Please use the setupWorker() function instead:
composeMocks() function is deprecated. Please use the setupWorker() function instead:- import { composeMocks, rest } from 'msw'
+ import { setupWorker, rest } from 'msw'
- const { start } = composeMocks(...)
+ const { start } = setupWorker(...)
Using start({ quiet: true }) now also silences the mocking activation message (#111, #118)
start({ quiet: true }) now also silences the mocking activation message (#111, #118)> This release bumps the integrity of mockServiceWorker.js. Please follow the error instructions in your browser's console to update the worker file t
This release bumps the integrity of
mockServiceWorker.js. Please follow the error instructions in your browser's console to update the worker file to the latest version.
start() function now accepts an options object:- start('./custom/sw/path.js', { ... })
+ start({ serviceWorker: { url: './custom/sw/path.js', options: { ... } })
start function now support a quiet option, allowing to opt-out from the logs in browser's console (#111, #113)start({ quiet: true })
msw throwing a type violation when used with TypeScript v3.7 (unsupported export * as syntax) (#114, #117, ).ramda dependency.Nothing published for this version
> This release introduces changes to mockServiceWorker.js file. Upon updating, you will be asked to update your Service Worker file. Please follow the
This release introduces changes to
mockServiceWorker.jsfile. Upon updating, you will be asked to update your Service Worker file. Please follow the instructions in the browser’s console to update the file.
ctx.cookie() (#101, #103).rest.post('/login', (req, res, ctx) => {
return res(
ctx.cookie('auth-token', 'abc-123')
)
})
> This change would bump the integrity of the Service Worker. Please follow the instructions in the respective error message in your browser's console
This change would bump the integrity of the Service Worker. Please follow the instructions in the respective error message in your browser's console to update the Service Worker file.
> This release introduces changes to the mockServiceWorker.js file. You will be advised to update that file in your application. Please follow the ins
This release introduces changes to the
mockServiceWorker.jsfile. You will be advised to update that file in your application. Please follow the instructions in the related error message in your browser's console.
start() function would resolve sooner than the Service Worker enabled the mocking (#73, #90)> This release introduces changes to the mockServiceWorker.js file. You will be advised to update that file in your application. Please follow the ins
This release introduces changes to the
mockServiceWorker.jsfile. You will be advised to update that file in your application. Please follow the instructions in the related error message in your browser's console.
POST request performed a GET request instead (#77, #84)Failed integrity assertions now leave the mocking enabled for the purpose of better developer experience (#87). It's still highly recommended to updat
Nothing published for this version
Nothing published for this version
The library now runs an integrity check against the Service Worker registered in your application (#81). This is necessary to warn you when the Servic
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Added support for Response patching
req object now contains new properties: integrity, destination, keepalive, bodyUsedreq.params being null, causing an exception when trying to access an existing parameterRunning start() and stop() functions now returns a Promise that corresponds to the Service Worker registration/unregistration status
start() and stop() functions now returns a Promise that corresponds to the Service Worker registration/unregistration statusimport { composeMocks, rest } from 'msw'
const { start, stop } = composeMocks(
rest.get(...)
)
start.then(() => {/* Your logic here */})
stop.then(() => {/* Your logic here */})
Demands a command to be run with npx msw
npx msw (#61)npx msw init command (#61): outputs the link to the docsRequest URI matching now ignores trailing slashes (#57, #62)
Adds support for mocking GraphQL queries and mutations
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →