gen-test

Generate Vitest test files for TypeScript source files following project conventions.

Updated Jan 4, 2026
One-click install
npx skills add https://github.com/threadedstack/threadedstack --skill gen-test-threadedstack
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: gen-test
Source: https://github.com/threadedstack/threadedstack/tree/main/.claude/skills/gen-test
Command: npx skills add https://github.com/threadedstack/threadedstack --skill gen-test-threadedstack

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing unit tests that match a monorepo's established conventions is repetitive and error-prone. This Skill generates Vitest test files that follow the project's exact structure, mocking patterns, and coverage requirements, so tests are consistent across all repos. ## Core Features & Use Cases - Convention-Aligned Test Generation: Produces co-located test files (foo.ts → foo.test.ts) using backtick describe/it strings, "should" naming, and vi.clearAllMocks() setup. - Mock Pattern Templates: Provides ready-made patterns for module mocking, Express req/res API mocking, and frontend fetch mocking. - Coverage Enforcement: Ensures happy paths, error handling (401/403/404/500), edge cases, and auth checks are covered. - Use Case: Ask for tests for a backend controller, and the Skill reads the source file, checks repo-specific patterns, references existing tests, generates the test file with correct path aliases (e.g., @TBE/*), and runs pnpm --filter <package> test to verify. ## Quick Start Generate Vitest tests for the source file src/controllers/userController.ts following the project conventions.

Frequently Asked Questions about gen-test

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate Vitest tests for a TypeScript file?▼

Provide the source file path and the Skill reads its exports and logic, checks repo-specific patterns, references existing tests for style, then generates a co-located test file. It runs pnpm --filter <package> test to verify the tests pass.

How to mock Express request and response in Vitest?▼

Create mockReq and mockRes as Partial types with vi.fn() for json and status methods, where status returns mockRes for chaining. Reset them in beforeEach along with vi.clearAllMocks() to isolate each test.

What test coverage should Vitest unit tests include?▼

Tests should cover happy paths, error handling such as 401, 403, 404, and 500 for APIs or thrown errors for utilities, edge cases like empty or null inputs, and auth or permission checks where applicable.

Does Vitest support module mocking with vi.mock?▼

Yes, vi.mock replaces a module's exports at the top of the test file before tests run. For example, mock a logger module by providing an object with vi.fn() stubs for each method like error, warn, and info.

Where should Vitest test files be located in a project?▼

This project co-locates test files with source files, so foo.ts gets foo.test.ts and foo.tsx gets foo.test.tsx in the same directory. Each repo configures Vitest via configs/vitest.config.ts.