How to use the msw.composeMocks function in msw

To help you get started, we’ve selected a few msw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github open-draft / msw / example / src / mocks / index.js View on Github external
import { composeMocks, rest } from 'msw'
import userMocks from './user'

const { start } = composeMocks(
  ...userMocks,
  rest.get('https://api.github.com/users/:username', (req, res, { json }) => {
    const { username } = req.params

    return res(
      json({
        avatar_url: 'https://i.imgflip.com/wnv7r.jpg',
        login: username,
        name: 'John Maverick',
        public_repos: Math.ceil(Math.random() * 100),
      }),
    )
  }),
)

start()

msw

Seamless REST/GraphQL API mocking library for browser and Node.js.

MIT
Latest version published 6 days ago

Package Health Score

94 / 100
Full package analysis