AgentSkillsCN

frontend-unit-test

使用 Vitest 或 Jest 为 JavaScript/TypeScript 以及前端项目编写单元测试。当您需要编写或运行测试时,可选用此技能。

SKILL.md
--- frontmatter
name: frontend-unit-test
description:
  Writes unit tests for JavaScript/TypeScript and frontend projects using Vitest
  or Jest. Use when writing or running tests.

Unit Test Protocol

Framework Detection

Never assume Jest or Vitest. Detect first:

  • Check imports in test files
  • Check config: vitest.config.*, jest.config.*
  • Check package.json dependencies (workspace-specific in monorepos)
  • Grep test scripts in package.json

Running Tests

Run relevant tests only unless explicitly requested:

bash
pnpm run test path/to/file.test.ts
# monorepo: cd apps/demo-app && pnpm run test path/to/file.test.ts

For all tests, use test script in closest package.json:

bash
pnpm run test
# monorepo: cd apps/demo-app && pnpm run test