@espoc/storybook-addon-mock

中文文档
10.1.2发布于 2026/10/06MITTypeScriptES Module近 30 天下载 1.6万

A storybook addon to mock fetch/XHR request

原始使用文档
文档目录4 节
  1. Purpose
  2. Highlights
  3. Documentation
  4. License
Storybook addon mock

Storybook Addon Mock

Actions Status Npm download npm version License

NPM

This addon allows you to mock fetch or XMLHttprequest requests in storybook. If your component depends on backend requests, and your backend requests are not ready yet to feed your component, this addon provides mock response to build your component.

Purpose

There are few packages those help the developers to mock the backend requests while building components. But those packages aren't integrated properly in storybook and also there's no scope to play with those requests in the storybook. Mostly, there's no playground to modify the response and see the changes in the storybook.

Highlights

storybook-addon-mock provides the following features.

  • You can mock fetch or XMLHttpRequest.
  • A dedicated panel where you can see the list of mock requests.
  • An on/off button for each request which can turn off the mock and try the real request.
  • A dropdown list of status code where you can change the status and experience the difference.
  • A response JSON object which can be modified in the panel. You can see the changes straight away in the story.
  • A delay option which helps you delaying the response so that you can test any kind of loading behaviour.

Documentation

See the documentation

Older(2.*) version documentation

License

This project is licensed under the MIT License - see the LICENSE file in the source code for details.

版本与发布记录

@espoc/storybook-addon-mock 共发布 3 个版本,首次发布于 2025/11/19;过去 12 个月发布了 3 个版本。

版本发布日期距今
10.1.2latest2026/10/061 个月前
10.1.12025/12/0211 个月前
10.0.02025/11/1911 个月前

关于 @espoc/storybook-addon-mock 的常见问题

@espoc/storybook-addon-mock 是什么?

A storybook addon to mock fetch/XHR request

如何安装 @espoc/storybook-addon-mock?

在项目目录运行 npm install @espoc/storybook-addon-mock,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:storybook(^10.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@espoc/storybook-addon-mock 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@espoc/storybook-addon-mock 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@espoc/storybook-addon-mock 可以商用吗?

@espoc/storybook-addon-mock 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@espoc/storybook-addon-mock 的下载量有多少?

根据 npm 官方下载统计,@espoc/storybook-addon-mock 在 2026/10/14 – 2026/11/12 这 30 天内被下载 16,057 次,日均约 535 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@espoc/storybook-addon-mock 还在维护吗?

最新版本 10.1.2 发布于 2026/10/06(1 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2025/11/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。