Seamless REST/GraphQL API mocking library for browser and Node.js.
MIT License
Bot releases are hidden (Show)
/foo/bar?
);/foo/bar+
).string | string[]
(#999).RequestParams
generic now follows the RequestBodyType
generic, changing its order (#999):rest.post<RequestBodyType, RequestParams, ResponseBodyType>() {}
RequestParams
type (#999). Please use the PathParams
type instead.- import { RequestParams } from 'msw'
+ import { PathParams } from 'msw'
document.baseURI
(previously location.origin
) in a browser-like environments (#1007, #1008).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' }
})
)
})
SetupWorkerApi
and SetupServerApi
from the browser and Node.js modules respectively (#994).typescript
as a peerDependency
to control supported TypeScript versions (#985).graphql.operation
handler producing a warning unable to intercept anonymous operations (#918, #904).inquirer
dependency version to 8.1.5 to propagate the fix for the Unexpected token “?”
issue when using MSW CLI (#917).TypeError: Failed to execute 'XXX' on 'Response': body stream already read
error when reading the original response body in the fallback mode (https://github.com/mswjs/interceptors/pull/152).@mswjs/cookies
and @mswjs/interceptors
as external packages so that their updates propagate to you automatically upon new installations of msw
..events
property on the worker/server (#868).-worker.on('request:start', listener)
+worker.events.on('request:start', listener)
-server.on('response:mocked', listener)
+server.events.on('response:mocked', listener)
.removeListener()
and .removeAllListeners()
methods (#868).// Removes all life-cycle event listeners you've attached to this server instance.
server.events.removeAllListeners()
onUnhandledRequest
option now throws an exception to halt running tests (#856).@mswjs/interceptors
package to propagate the xmldom
security update (#876).Cookie
/Set-Cookie
response headers via ctx.set
now produces a type violation (#819). Please use ctx.cookie
instead.resolutionContext
option on handleRequest
API to specify the baseUrl
for all relative request handler URLs (#830).IncomingMessage
body of the original response in Node.js (https://github.com/mswjs/interceptors/pull/140, #785).Published by kettanaito over 3 years ago
setTimeout
issue in Socket (https://github.com/mswjs/interceptors/pull/120, #812)rest.get('/polling/:maxCount', function* (req, res, ctx) {
const { count } = req.params
let count = 0
while (count < req.params. maxCount) {
yield res(ctx.json({ count }))
}
return res(ctx.json({ done: true }))
})
ctx.cookie
utility to the GraphQL handlers (#763).mockServiceWorker.js
) now contains the library version number to improve its inspection and debugging across releases (#781).onUnhandledRequest
default behavior (#740).onUnhandledRequest
option is set to "warn"
by default (previously ”bypass"
) (#703).npx msw init
now recursively creates a non-existing worker directory (#699).setupServer
(https://github.com/mswjs/interceptors/pull/116).xhrInstance.responseXML
in Node.js (#715).Content-Type
header (#671).response
instance in the life-cycle events now handles response.headers
as the Headers
instance (#660).server.on('response:bypass', (res) => {
- res.headers['content-type']
+ res.headers.get('content-type')
})
setupServer
no longer applies request interception immediately. Instead, it's applied when called server.listen()
(#660).XMLHttpRequest
in Node.js (https://github.com/mswjs/interceptors/pull/102).superagent
(#632).DropFirstInTuple
type used internally in compose.ts
(#658).RestHandler
class publicly.Uncaught ReferenceError: process is not defined
exception when calling worker.start()
(#609, #629).PickLastInTuple
type (#615, #627).TypeError: Object.fromEntries is not a function
error when running MSW in Node.js v10 (#625, #633).[email protected]