Docs 测试
Storybook Docs

如何使用 Storybook 测试 UI

Storybook 提供了一个独立的测试环境,用于隔离测试组件。无论组件多么复杂,故事都能让你轻松探索其所有变体。

¥Storybook provides a clean-room environment for testing components in isolation. Stories make it easy to explore a component in all its variations, no matter how complex.

这意味着用户故事是 UI 测试策略的实用起点。编写故事已是 UI 开发过程中的自然组成部分,测试这些故事是一种低成本的 UI 错误预防方法。

¥That means stories are a pragmatic starting point for your UI testing strategy. You already write stories as a natural part of UI development, testing those stories is a low-effort way to prevent UI bugs over time.

最简单的测试方法是手动“抽查”。你只需在本地运行 Storybook,然后逐个检查每个故事的外观和行为即可。使用 发布 在线运行 Storybook,以便共享复现步骤并让团队成员参与其中。

¥The simplest testing method is manual “spot checking”. You run Storybook locally, then eyeball every story to verify its appearance and behavior. Publish your Storybook online to share reproductions and get teammates involved.

要单独测试组件,通常需要模拟数据、依赖,甚至网络请求。查看我们的 Storybook 中的模拟 指南了解更多信息。

¥To test a component in isolation, you often have to mock data, dependencies, or even network requests. Check out our guide on mocking in Storybook for more info.

Storybook 还附带工具 测试运行器,并与更广泛的 JavaScript 生态系统进行了便捷集成,以扩展你的 UI 测试覆盖范围。这些文档详细介绍了如何使用 Storybook 进行 UI 测试。

¥Storybook also comes with tools, a test runner, and handy integrations with the larger JavaScript ecosystem to expand your UI test coverage. These docs detail how you can use Storybook for UI testing.