Releases: mswjs/msw
Releases · mswjs/msw
v0.19.3
v0.19.2
v0.19.1
v0.19.0
Features
- The library now defers all the client-side requests that happen between calling
worker.start()
and successful worker activation. This eliminates race condition between the two, and now comes as the default behavior. (#190, #196)
The behavior of deferring requests can be configured using the waitUntilReady: boolean
option on worker.start()
:
import { setupWorker, rest } from 'msw'
const worker = setupWorker(/* request handlers */)
worker.start({
// You can opt-out of the deferred network requests behavior.
waitUntilReady: false
})
v0.18.1
v0.18.0
Features
- Adds support for declaring runtime request handlers (#128, #187):
.use()
to prepend any request handlers. Any prepended request handlers take priority over existing ones, if their predicate match..restoreHandlers()
to mark any used one-time request handlers as unused, allowing them to affect network again..resetHandlers()
to remove any request handlers added on runtime. Optionally accepts a list of next request handlers that replace the initial handlers passed tosetupServer
/setupWorker
call.
- Adds support for one-time request handlers using
res.once()
. Such handles will respond with a given mocked response only once upon request match:
rest.get('/books', (req, res, ctx) => {
return res.once(ctx.json([1, 2, 3]))
})
Bug fixes
TS7016: Could not find a declaration file for module 'cookie'
- Fixes an outdated GitHub repository link in the
mockServiceWorker.js
file.
v0.17.2
v0.17.1
v0.17.0
Features
- Custom request handlers have reworked lifecycle and accept new methods:
parse()
, to retrieve additional information about the request before the predicate.getPublicRequest()
, to modify the original request with public information (i.e. addingreq.params
orreq.variables
).
Bug Fixes
v0.16.2
Features
- GraphQL requests are now being printed into browser’s console using a proper format (operation name / response status) (#161, #174)
- Each custom request handler can have its own
log
function that controls what and how gets printed into browser’s console for introspection:
// my-handler.js
export const myHandler = () => {
return {
log(req, res, handler) {
console.log('%s %s', req.method, req.url.href)
}
}
}
The information available in the log
function:
req
, intercepted request instance;res
, resolved mocked response object;handler
, exact request handler that captured this request.