A Storybook addon for mocking fetch and XMLHttpRequest requests in component stories. Version 6.0.1 requires Storybook 9.0.12+ and React 16.8+. It provides a dedicated panel to view, enable/disable, modify status codes, edit JSON responses, and add delay. Unlike other mocking libraries, it integrates directly with Storybook's UI for an interactive debugging experience. Ships TypeScript types.
npm install storybook-addon-mockNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Add storybook-addon-mock to Storybook and use the withMock decorator with mockData parameter to intercept fetch/XHR requests.
Update Storybook to version ^9.0.12 and ensure addon peer dependency is satisfied.
Add decorators: [withMock] to your story default export or globally in .storybook/preview.js.
Ensure the url property exactly matches the request URL, including query strings. Use ?key=value format if needed.
Use import type { MockPayload } from 'storybook-addon-mock' to avoid emitting unused JavaScript.Run npm install storybook-addon-mock --save-dev or yarn add storybook-addon-mock --dev.
Add decorators: [withMock] to your story default export or globally.
Ensure your component renders a wrapper element or ignore the warning.