Skip to content

Releases: mswjs/msw

v0.20.4

10 Aug 07:19
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue that produces a "Must provide source" error during GraphQL parsing of POST requests with body, but without the query property (#234, #328, #329).
  • Fixes an issue that resulted into http module being patched in React Native environment, where it's not present (#203, #331).

Dependencies

v0.20.3

06 Aug 07:33
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue that resulted into the first matching request handler being treated as the only relevant request handler, even if it doesn't return any mocked response (#234, #258, #265).

v0.20.2

05 Aug 08:39
Compare
Choose a tag to compare

Features

  • Adds graphql.link request handler that allows to mock GraphQL operations on per-endpoint basis (#315, #319).
import { setupWorker, graphql } from 'msw'

const github = graphql.link('https://api.github.com/graphql')
const stripe = graphql.link('https://api.stripe.com/graphql')

const worker = setupWorker(
  github.query('GetUser', resolver),
  stripe.mutation('Payment', resolver),
)

worker.start()

Bug fixes

  • Fixes a TypeScript issue that resulted into the following error (#321, #322):
ERROR in node_modules/msw/lib/types/context/cookie.d.ts:1:8 - error TS1192:
Module '"/node_modules/@types/cookie/index"' has no default export.

v0.20.1

31 Jul 08:22
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue with the node-fetch dependency that wasn't listed as a save dependency (#308)
  • Fixes an issue that resulted into the React Native build module at /native not being published to NPM (#309)

v0.20.0

30 Jul 12:58
Compare
Choose a tag to compare

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).

v0.19.5

24 Jun 07:11
Compare
Choose a tag to compare

Features

  • Adds a warning when using redundant query parameters in a request handler URL (#231, #233).
  • Throws an exception when running setupWorker in a NodeJS environment (#219).
  • Throws an exception when running setupServer in a browser environment (#214, #219).
  • Adds a custom error message when calling worker.start() and the worker script doesn’t exist (#237, #242).
  • Exports GraphQL type annotations for GraphQLMockedRequest, GraphQLMockedContext, GraphQLRequestPayload, GraphQLResponseResolver types (#213, #241).

Bug fixes

  • Sets the default realistic response time of ctx.delay() to 5ms when run in Node environment (including jsdom) (#205).
  • Fixes an issue that resulted into the response Promise to never resolve when using jest.useFakeTimers() in your tests (#243).
  • Fixes a bug that resulted into a request handler URL with query parameters to produce a false negative match with the identical actual request URL. Query parameters and hashes in a request handler URL no longer affect the matching process.

v0.19.4

20 Jun 17:14
Compare
Choose a tag to compare

Internal

  • Updates the repository's homepage and README.

v0.19.3

13 Jun 15:40
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue that resulted into GraphQL requests issued using a GET method not being intercepted (#210, #212).

v0.19.2

13 Jun 09:58
Compare
Choose a tag to compare

Bug fixes

  • Fixes an issue that resulted into TypeError [ERR_INVALID_URL]: Invalid URL: undefined//undefined exception when using third-party request issuing libraries in Node (#209, #211).

v0.19.1

12 Jun 12:26
Compare
Choose a tag to compare

Features

  • Calling ctx.delay() without any arguments now simulates a random realistic server response time in a range between 100-400ms (#192, #198). Responses in Node are instantaneous.

Bug fixes

  • Fixes an issue that resulted into Uncaught (in promise) SyntaxError: Unexpected end of input exception when processing a request. Internally, a request’s body is now always retrieved as text, parsing it as JSON is delegated to the client side (based on the Content-Type header) (#200, #201).