AgentSkillsCN

vitest-test-creator

借助Vitest进行测试代码的编写、重构与调试。支持单元测试(.unit.test.ts)以及React组件与Hooks测试(.browser.test.tsx)。当用户说“编写测试”“添加测试用例”“重构测试”“按规范修复此测试”等指令时,可使用此技能,用于创建、编辑或优化.test.ts/.test.tsx文件。

SKILL.md
--- frontmatter
name: vitest-test-creator
description: Test code creation, refactoring, and debugging with Vitest. Supports unit tests (.unit.test.ts) and React component/Hooks tests (.browser.test.tsx). Use when the user says "write tests", "add test cases", "refactor tests", "fix this test according to guidelines", etc. Use for creating, editing, or improving .test.ts/.test.tsx files.

Vitest Test Creator

Project-Specific Test Types

Test TypeFile PatternEnvironmentTarget
Unit Test*.unit.test.tsNode.jsPure functions in utils/, lib/
Browser Test*.browser.test.tsxPlaywright (Chromium)React components, hooks

See file-layout.md for placement rules.

Key Guidelines

  • Always call cleanup() in afterEach for browser tests
  • Use container.querySelector() instead of screen.getByRole() to avoid multiple element errors
  • jest-dom matchers require .browser.test.tsx extension and vitest.setup.ts import

References