testing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTesting
测试
Write reliable tests with Vitest v4 dual configuration.
使用Vitest v4双配置编写可靠的测试用例。
Activation Conditions
激活条件
- Writing or modifying tests
- Debugging test failures
- Setting up mocks
- Questions about test configuration
- 编写或修改测试用例
- 调试测试失败问题
- 设置模拟(mock)项
- 测试配置相关问题
Quick Reference
快速参考
| Action | Rule |
|---|---|
| Choose test type | |
| Mock modules | |
| Test stores | |
| Mock Connect APIs | |
| Skip UI rendering tests | |
| 动作 | 规则 |
|---|---|
| 选择测试类型 | |
| 模拟模块 | |
| 测试存储 | |
| 模拟Connect API | |
| 跳过UI渲染测试 | |
Commands
命令
bash
bun run test # All tests (CI default)
bun run test:ci # Sequential for CI
bun run test:unit # Unit tests only
bun run test:integration # Integration tests only
bun run test:ui # Interactive UI
bun run test:watch # Watch mode
bun run test:coverage # Coverage reportbash
bun run test # All tests (CI default)
bun run test:ci # Sequential for CI
bun run test:unit # Unit tests only
bun run test:integration # Integration tests only
bun run test:ui # Interactive UI
bun run test:watch # Watch mode
bun run test:coverage # Coverage reportKey Points
要点
- = unit (Node.js),
.test.ts= integration (JSDOM).test.tsx - Always use for React component tests
test-utils/test-utils.tsx - Test that features are fully wired: UI elements must connect to actual functionality
- = 单元测试(Node.js环境),
.test.ts= 集成测试(JSDOM环境).test.tsx - React组件测试请始终使用
test-utils/test-utils.tsx - 测试功能是否完全连通:UI元素必须关联到实际功能
Feature Completeness Testing
功能完整性测试
When implementing interactive features (buttons, forms, etc.):
- Verify event handlers call the correct functions with proper parameters
- Test that AbortSignals, callbacks, and other "plumbing" are passed through
- Don't assume UI presence means functionality works - test the connection
实现交互功能(按钮、表单等)时:
- 验证事件处理程序以正确参数调用对应函数
- 测试AbortSignals、回调函数以及其他「链路」是否正确传递
- 不要假设UI存在就代表功能可用 - 需测试连接逻辑
When to Use This Skill
何时使用本技能
- Writing or
.test.tsfiles.test.tsx - Mocking modules, stores, or transports
- Component behavior tests
NOT for: Multi-page user workflows → use e2e-tester
- 编写或
.test.ts文件时.test.tsx - 模拟模块、存储或传输层时
- 组件行为测试
不适用场景: 多页面用户工作流 → 请使用e2e-tester
Rules
规则
See directory for detailed guidance.
rules/查看目录获取详细指南。
rules/