| name | tdd-vitest |
| description | Use ONLY when working with TypeScript and Vitest test files in this project.
Provides rules for test file creation, running tests via npm scripts, and TDD best practices.
|
TDD with TypeScript and Vitest
Test File Creation
- Create specification file with
.spec.ts extension
- Import with explicit extensions for local modules (e.g.,
from "./module.js")
- Use Vitest testing functions (
describe, it, expect)
- Follow TDD red-green-refactor cycle
- Leverage TypeScript's type checking during development
Running Tests — CRITICAL REQUIREMENTS
🚨 ALWAYS use npm scripts defined in package.json
✅ CORRECT — Use npm scripts:
npm test
npm run test:watch
❌ WRONG — DO NOT use these:
npx vitest
vitest --run SomeFile.spec.ts
npx vitest SomeFile.spec.ts
Why This Matters
- npm scripts provide a consistent interface for running tests
- Configuration is managed centrally in package.json
- Consistency across development and CI environments
Example Test Template
import { describe, it, expect } from "vitest";
import { calculate } from "./calculator.js";
describe("Calculator", () => {
it.todo("should handle basic operations");
it.todo("should validate input types");
it.todo("should handle edge cases");
});