Packages

msw

3.0.7 · 18 Nov 2026MIT36M / weekRepositoryHomepagenpmAtom feed

Your version

0.36.0

4 Dec 2021Where it was published

0.49.3 is the newest release of 0.36.x.

In short

2 breaking6 new4 fixed2 internal

  • Breaking

    Request path parameters are now annotated as ambiguous string | string (#999).

  • Breaking

    Relative requests are now resolved against document.baseURI (previously location.origin) in a browser-like environments (#1007, #1008).

Release note

Breaking changes

  • Breaking

    Uses path-to-regexp for URL matching (#691, #888). This makes the path matching experience identical to such in ExpressJS, and enabled various new features:

    • Optional path segments (/foo/bar?);

    • Repeating groups (/foo/bar+).

  • Breaking

    Request path parameters are now annotated as ambiguous string | string (#999).

  • Breaking

    The RequestParams generic now follows the RequestBodyType generic, changing its order (#999):

rest.post<RequestBodyType, RequestParams, ResponseBodyType>() {}
  • Breaking

    Removes the RequestParams type (#999). Please use the PathParams type instead.

- import { RequestParams } from 'msw'
+ import { PathParams } from 'msw'
  • Breaking

    Relative requests are now resolved against document.baseURI (previously location.origin) in a browser-like environments (#1007, #1008).

Features

  • Adds a new rest.all() request handler (#896). This handler captures all REST API requests regardless of method.

import { rest } from 'msw'

rest.all('/api/*', (req, res, ctx) => {
  // Intercepts all requests to "/api/*"
  // regardless of their method.
})
  • Supports encoded request path components (#980).

  • Supports mocking GraphQL extensions (#981).

graphql.query('GetUser', (req, res, ctx) => {
  return res(
    ctx.extensions({
      message: 'Mocked extension',
      tracking: { version: '1.2.3' }
    })
  )
})
  • Exports SetupWorkerApi and SetupServerApi from the browser and Node.js modules respectively (#994).

Bug fixes

  • Specifies typescript as a peerDependency to control supported TypeScript versions (#985).

  • Fixes an issue that resulted in graphql.operation handler producing a warning unable to intercept anonymous operations (#918, #904).

  • Locks inquirer dependency version to 8.1.5 to propagate the fix for the Unexpected token “?” issue when using MSW CLI (#917).

  • Fixes an issue that resulted in the TypeError: Failed to execute 'XXX' on 'Response': body stream already read error when reading the original response body in the fallback mode (#152).

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.