msw
3.0.7 · 18 Nov 2026MIT36M / weekRepositoryHomepagenpmAtom feed
0.49.3 is the newest release of 0.20.x.
In short
1 breaking5 new7 fixed
- Breaking
composeMocksfunction has been removed (#236, #239). Please usesetupWorkerinstead.
Release note
Breaking changes
-import { composeMocks, rest } from 'msw'
-composeMocks(rest.get(...))
+import { setupWorker, rest } from 'msw'
+setupWorker(rest.get(...))Features
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: mswjs.io/docs/api/setup-server
Adds support for binary response types (#221, #224, Binary response type recipe).
Adds an option to warn/error/execute arbitrary logic on unmatched request (#191,
setupWorkerdocs,setupServerdocs).
const server = setupServer(
rest.get('/books', (req, res, ctx) => res())
)
server.listen({
onUnhandledRequest: 'error'
})
fetch('/user') // ERROR! Unhandled request.Adds a
req.cookiesproperty to access a request’s cookies (#199, #261, Accessing request cookies recipe).Adds support for network error emulation (#253,
res.networkErrorAPI):
rest.post('/login', (req, res, ctx) => {
return res.networkError('Custom error message')
})Bug fixes
Fixes an issue that resulted into a "global is not defined" error being thrown in a browser (#255).
Fixes an issue that resulted into the worker listeners being established multiple times after repetitive calls to
worker.start()or Hot Reload (#244).Fixes an issue that failed response patching in NodeJS (#264, #266).
Fixes an issue that resulted into the
XMLHttpRequest.prototype.addEventListenerevents being ignored (#267).Fixes an issue that resulted into timeout in POST requests with a body in NodeJS (#277).
Fixes an invalidly typed
req.bodyin case of GraphQL request (#297, #302).Updates library's dependencies (#306).
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.