testing
使用Vitest和Testing Library编写测试。用于创建单元测试、API测试、组件测试或模拟Firebase/外部服务。包括测试模式、断言和覆盖率目标。
📖 中文导读:使用Vitest和Testing Library编写测试。用于创建单元测试、API测试、组件测试或模拟Firebase/外部服务。包括测试模式、断言和覆盖率目标。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。
name: testing description: Writes tests using Vitest and Testing Library. Use when creating unit tests, API tests, component tests, or mocking Firebase/external services. Includes test patterns, assertions, and coverage targets.
Testing Skill
Instructions
- Place tests in
src/__tests__/ - Use
describe/it/expectpattern - Mock Firebase with helpers in
helpers/mock-firebase.ts - Run:
pnpm test(watch) orpnpm test:run(once)
Test Template
import { describe, it, expect, beforeEach, vi } from 'vitest'
describe('functionName', () => {
beforeEach(() => vi.clearAllMocks())
it('should do something when condition', () => {
const result = functionName(input)
expect(result).toBe('expected')
})
it('should throw error for invalid input', () => {
expect(() => functionName(null)).toThrow('Error')
})
})
Common Assertions
expect(value).toBe(expected)
expect(value).toEqual({ key: 'value' })
expect(array).toContain(item)
expect(fn).toHaveBeenCalledWith(arg)
expect(async () => await fn()).rejects.toThrow()
Coverage Targets
- Statements: 80%
- Branches: 70%
- Functions: 80%
For mocking patterns, API testing, and component testing, see reference.md.