Breaking changes
- 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+
).
- Optional path segments (
- Request path parameters are now annotated as ambiguous
string | string[]
(#999). - The
RequestParams
generic now follows theRequestBodyType
generic, changing its order (#999):
rest.post<RequestBodyType, RequestParams, ResponseBodyType>() {}
- Removes the
RequestParams
type (#999). Please use thePathParams
type instead.
- import { RequestParams } from 'msw'
+ import { PathParams } from 'msw'
- Relative requests are now resolved against
document.baseURI
(previouslylocation.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.
})
graphql.query('GetUser', (req, res, ctx) => {
return res(
ctx.extensions({
message: 'Mocked extension',
tracking: { version: '1.2.3' }
})
)
})
- Exports
SetupWorkerApi
andSetupServerApi
from the browser and Node.js modules respectively (#994).
Bug fixes
- Specifies
typescript
as apeerDependency
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 theUnexpected 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 (mswjs/interceptors#152).
Internal
- Lists
@mswjs/cookies
and@mswjs/interceptors
as external packages so that their updates propagate to you automatically upon new installations ofmsw
. - Updates dependencies.