offbeat-dev / storybook-msw-addon

An MSW (Mock Service Worker) addon including a control panel that enables interaction and manipulation of mock requests within Storybook.
https://storybook-msw-addon.vercel.app
MIT License
25 stars 5 forks source link

Add ability to register initial handlers #7

Closed kpervin closed 7 months ago

kpervin commented 7 months ago

Add ability, like msw-storybook-addon, to initialize handlers at root level:

// preview.js
import { initialize } from 'msw-storybook-addon';

initialize({}, [
  rest.get('/numbers', (req, res, ctx) => {
    return res(ctx.json([1, 2, 3]))
  }),
  rest.get('/strings', (req, res, ctx) => {
    return res(ctx.json(['a', 'b', 'c']))
  }),
])