Packages

msw

3.0.7 · 18 Nov 2026MIT36M / weekRepositoryHomepagenpmAtom feed

Your version

0.20.0

30 Jul 2020Where it was published

0.49.3 is the newest release of 0.20.x.

In short

1 breaking5 new7 fixed

  • Breaking

    composeMocks function has been removed (#236, #239). Please use setupWorker instead.

Release note

Breaking changes

  • Breaking

    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(...))

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 setupServer API for React Native is the exact mirror of the same API for NodeJS. Read more in the documentation: mswjs.io/docs/api/setup-server

const server = setupServer(
  rest.get('/books', (req, res, ctx) => res())
)

server.listen({
  onUnhandledRequest: 'error'
})

fetch('/user') // ERROR! Unhandled request.
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.addEventListener events being ignored (#267).

  • Fixes an issue that resulted into timeout in POST requests with a body in NodeJS (#277).

  • Fixes an invalidly typed req.body in 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.