{"repo":"mswjs/msw-storybook-addon","free":true,"listed":false,"github":"https://github.com/mswjs/msw-storybook-addon","clone":"git clone https://github.com/mswjs/msw-storybook-addon.git","description":"Mock API requests in Storybook with Mock Service Worker.","language":"TypeScript","stars":494,"topics":["storybook","addon","msw","api","mock","worker","story"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"MSW Storybook Addon Mock API requests in Storybook with Mock Service Worker. Usage Install Make sure you have msw@2.x installed as a peer dependency. Generate the worker script Next, use the MSW CLI to generate a worker script at the given path: Replace ./public with the path to your static directory of Storybook. Configure Storybook CSF 3.0 The loader API for CSF 3.0 is deprecated . Please consider using the CSF Next API instead. Include the addon's types in your tsconfig.json for a type safe parameters.msw experience in your setup and stories: CSF Next If you are using the CSF Next syntax (also known as CSF Factories), it's enough to import and call the addon function in preview.ts : parameters.msw is not supported in CSF Next. It is preserved only for CSF 3.0 to make migration easier — use the beforeEach hook instead. Include the addon's types in your tsconfig.json for a type-safe experience in your setup and stories: Custom worker setup By default, the addon creates and starts the worker for you: it starts quietly and ignores common asset and Storybook-internal requests. To customize that behavior (e.g. worker.start() options or initial handlers), provide a setup function that creates the worker, starts it, and returns it. In CSF 3.0, pass it to mswLoader : In CSF Next, pass it to addonMsw : Handlers passed to setupWorker() act as initial handlers and survive the automatic handler reset between stories. Provide handlers If you have correctly installed and configured this ","default_branch":null,"files":null,"tree":[],"storefront":"/r/mswjs","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/mswjs/msw-storybook-addon/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}