A Storybook addon that integrates fetch-mock to mock fetch() calls in stories. Current stable version is 2.0.1, with quarterly releases. Supports Storybook 7, 8 and 'next' via @storybook/preview-api. Key differentiators vs alternatives: supports full Fetch mocking (unlike storybook-addon-mock which only handles basic cases), allows mocks as simple objects or resolver functions (like fetch-mock), and is a thin wrapper around the well-maintained fetch-mock library (available since 2015). Compared to MSW addon, it supports mock objects directly for APIs you don't control. Ships TypeScript types.
npm install storybook-addon-fetch-mockNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up the withMock decorator globally, then mocks a GET /api/users endpoint returning a JSON array.
Upgrade to Storybook 7+ and ensure @storybook/preview-api is installed as a peer dependency.
Use 'path:' prefix for relative URL matching, e.g., matcher: { url: 'path:/api/users' }.Set method as a plain string, not 'method: { method: 'GET' }'.Use unique matcher names or reset in beforeEach handler using fetchMock.reset().
Ensure story parameters object has fetchMock.mocks array: parameters: { fetchMock: { mocks: [] } }.Add a matching mock in parameters.fetchMock.mocks or allow unmatched requests by setting parameters.fetchMock.fallbackToNetwork.
Add withMock to your decorators array in .storybook/preview.js or per-story.