一键导入
testing-unit-vitest
Writes and maintains unit tests using Vitest. To be used for testing business logic in services and utilities.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Writes and maintains unit tests using Vitest. To be used for testing business logic in services and utilities.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Defines the Entity-Relationship (ER) model for the system based on the feature specifications. To be used for designing the data structures and relationships needed to implement the features.
Generates an Architecture Design Document (ADD) for software projects. To be used when designing a product architecture
Generates a Product Requirements Document (PRD) for software projects. To be used when analyzing a project to create a PRD.
Writes the specification with problem definition, solution outline, and acceptance criteria. To be used to specify a feature, bug correction, or enhancement.
Creates a detailed implementation plan for a given feature specification. To be used for planning the implementation of feature specifications.
Creates the base foundation for the agent's workflow. This prompt is used to set up the initial context and instructions for the agent.
| name | testing-unit-vitest |
| description | Writes and maintains unit tests using Vitest. To be used for testing business logic in services and utilities. |
When asked to write or maintain unit tests, follow these guidelines:
validation.spec.ts next to validation.ts){filename}.spec.ts patterntests/ directory for HTTP-layer integration testsUse describe/it blocks with arrange-act-assert pattern:
import { describe, it, expect, beforeEach, vi } from 'vitest';
describe('MyService', () => {
beforeEach(() => {
// Setup for each test
});
describe('methodName', () => {
it('should do something specific', () => {
// Arrange: Set up test data
const input = { /* ... */ };
// Act: Execute the code under test
const result = service.method(input);
// Assert: Verify the outcome
expect(result).toBe(expected);
});
});
});
Use vi.fn() for repository interfaces and external services:
import { vi } from 'vitest';
const mockRepo = {
save: vi.fn(),
findById: vi.fn(),
findAll: vi.fn(),
};
// Inject mocked repository
const service = new MyService(mockRepo);
// Set return values
vi.mocked(mockRepo.findById).mockReturnValue(mockData);
// Verify calls
expect(mockRepo.save).toHaveBeenCalledWith(expected);
expect(mockRepo.save).toHaveBeenCalledTimes(1);
npm run test:dev - Auto-rerun tests during developmentnpm run test:unit - Run all unit tests oncenpm run test:coverage - Generate coverage reportnpm test - Run Playwright tests independentlyit('should...') statementsexpect(value).toBe(expected); // Strict equality
expect(value).toEqual(expected); // Deep equality
expect(value).toBeInstanceOf(Class); // Instance check
expect(value).toBeUndefined(); // Undefined check
expect(array).toHaveLength(3); // Array length
expect(() => fn()).toThrow(ErrorClass); // Exception check
expect(mockFn).toHaveBeenCalledWith(arg); // Mock verification
expect(mockFn).toHaveBeenCalledTimes(1); // Call count
For advanced features, see Vitest documentation: