.agents/skills/testing-unit-vitest/SKILL.md
Writes and maintains unit tests using Vitest. To be used for testing business logic in services and utilities.
npx skillsauth add albertobasalo/astro-bookings-express testing-unit-vitestInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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:
testing
Writes end-to-end tests with Playwright. To be used for verifying acceptance criteria through automated tests.
testing
Creates a detailed implementation plan for a given feature specification. To be used for planning the implementation of feature specifications.
testing
Writes the specification with problem definition, solution outline, and acceptance criteria. To be used to specify a feature, bug correction, or enhancement.
documentation
Generates a Product Requirements Document (PRD) for software projects. To be used when analyzing a project to create a PRD.