yarn msw 0.20.0

latest releases: 2.3.0, 2.2.14, 2.3.0-ws.rc-6...
3 years ago

Breaking changes

  • 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

  • Adds React Native support (#203, #269).
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: https://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).

Don't miss a new msw release

NewReleases is sending notifications on new releases.