vitest
Writes fast, isolated unit and integration tests with Vitest. Use when each test must run on file-save without shared state — `vi.mock()` for external deps, `vi.spyOn()` for call monitoring, AAA structure, and edge-case coverage for null/undefined/boundary inputs.
- License 许可
- MIT
- 最近更新
- 2026-05-27
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- vitest
- vendor
- vitest
- description
- Writes fast, isolated unit and integration tests with Vitest. Use when each test must run on file-save without shared state — `vi.mock()` for external deps, `vi.spyOn()` for call monitoring, AAA structure, and edge-case coverage for null/undefined/boundary inputs.
03 SKILL.md 正文
Skill: Vitest
Policy Capsule
- Keep each test independent — never share mutable state between tests; reset mocks in
afterEach. - Mock external dependencies with
vi.mock(); usevi.spyOn()only to observe call shape, not to replace logic. - Structure tests as Arrange / Act / Assert — do not interleave the three phases.
- Use descriptive titles in the
describe('Component', () => { it('should [action] when [condition]') })form. - Cover error paths, null/undefined inputs, and boundary conditions, not just the happy path.
- Use snapshots only for large, stable data structures; avoid them for frequently changing UI to prevent snapshot fatigue.
- Aim for 80%+ coverage on business logic and edge cases; audit with
vitest --coverage. - Test observable behavior, not internal implementation details; refactors should not require rewriting passing tests.
Guidelines for writing fast, reliable unit and integration tests.
1. Core Principles
- Speed: Tests should be fast enough to run on every file save.
- Isolation: Each test must be independent. Avoid shared state between tests.
- Confidence: Tests should verify behavior, not implementation details.
2. Technical Standards
- Mocking: Use
vi.mock()for external dependencies (APIs, network calls) andvi.spyOn()for monitoring function calls. - Snapshot Testing: Use snapshots for large, stable data structures, but avoid them for frequently changing UI components to prevent "snapshot fatigue."
- Coverage: Aim for 80%+ coverage on business logic and edge cases. Use
vitest --coveragefor auditing.
3. Best Practices
- Descriptive Titles: Use the
describe('Component/Utility', () => { it('should [action] when [condition]') })pattern. - Arrange-Act-Assert (AAA): Structure tests clearly into setup (Arrange), execution (Act), and verification (Assert) phases.
- Edge Cases: Always include tests for error states, null/undefined inputs, and boundary conditions.
04 同仓库更多 Skills
no-capsule-skill
Fixture without a Policy Capsule section.
backend-security-patterns
Combined backend protocols for authentication (Clerk JWT verification) and PII-safe observability. Use when handling auth on the server, verifying Clerk webhooks via `svix`, scoping metadata via `publicMetadata`/ `privateMetadata`, or sanitizing logs to keep emails, tokens, and request bodies out of telemetry.
playwright
Robust E2E browser testing with Playwright. Use when writing browser-driven tests — leverage auto-waiting (no `waitForTimeout`), prefer user-visible locators (`getByRole`, `getByText`, `getByLabel`) over CSS/XPath, reuse `storageState` for auth, and enable trace-on-first-retry for CI debugging.
playwright-bdd
Wires Gherkin `.feature` files to Playwright via the `playwright-bdd` library. Use when running BDD scenarios on a Playwright runtime — pairs with the `gherkin-authoring` skill (scenario prose) and the `playwright` skill (browser conventions). Drives execution by tag expression with trace-first debugging and Playwright-native sharding.
lighthouse-baseline
Codifies the capture-and-check baseline pattern for long-running quality signals (Lighthouse scores, bundle size, p95 latency, runtime memory). Use when wiring a new metric that needs a baseline file, paired :capture / :check npm scripts, a tolerance-bounded gate, and a weekly refresh cadence — the goal is a hard CI signal that ratchets only with intent.
gherkin-authoring
Authors `.feature` files that stay business-readable, translate cleanly from PRD acceptance criteria, and reuse a shared step-definition library. Use when writing or editing scenarios — the SSOT enforcement rules live in `.agents/rules/gherkin-standards.md`; this skill shows authors how to apply them.