msw-storybook-addon v2.0.4
Features
- Mock Rest and GraphQL requests right inside your story.
 - Document how a component behaves in various scenarios.
 - Get a11y, snapshot and visual tests using other addons for free.
 
Quick Start
Install msw & storybook addon.
npm i -D msw msw-storybook-addonEnable msw on storybook by adding these lines in ./storybook/preview.js
import { addDecorator } from '@storybook/react'
import { initializeWorker, mswDecorator } from 'msw-storybook-addon'
initializeWorker()
addDecorator(mswDecorator)Generate service worker for msw in your public folder.
npx msw init public/Refer MSW official guide for framework specific paths.
Start storybook with that public folder.
npx start-storybook -s public -p 6006Mock API calls in a story.
import { rest } from 'msw'
export const SuccessBehavior = () => <UserProfile />
SuccessBehavior.parameters = {
  msw: [
    rest.get('/user', (req, res, ctx) => {
      return res(
        ctx.json({
          firstName: 'Neil',
          lastName: 'Maverick',
        })
      )
    }),
  ],
}The msw parameter takes an array of handlers as shown in MSW official guide.
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago