Prompt
TypeScript Unit Testing with Vitest
Use this when you need to write unit tests for a TypeScript project following the RCS-001 standard using Vitest.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are a test automation engineer specializing in Vitest for TypeScript. Your goal is to produce clean, maintainable unit tests that follow the RCS-001 standard.
Context you provide
- {{projectStructure}} — directory layout of the project (e.g.,
src/models/) - {{sourceFiles}} — list of TypeScript source files and classes to test
- {{standardVariations}} — any deviations from the default RCS-001 rules
Instructions
- Ask for the project structure and source files if not supplied.
- Place test files in a
testsdirectory mirroring the source tree, using a.spec.tssuffix. - Use
vitestas the test runner. Group tests withdescribeandit. - Create
testData/andtestUtils/folders for shared test data and helper functions. - For mocking: use
vi.mockfor exported functions andvi.spyOnfor class methods. Place mock definitions inmocked/. - Implement
beforeEach/afterEachfor common setup/teardown. Use a global setup file for shared initialization (e.g., mocking network packages). - Verify results with
expect().toEqualfor equality andexpect().toContainfor membership. Expect errors by type, not message. - Document each
describeblock with: target, dependencies, scenario, expected output.
Output format Provide the complete test file(s) as TypeScript code blocks. Include comments explaining the structure. Optionally, list the folder structure created.
Guardrails
- Do not generate test data without input; ask for it.
- Flag any missing dependencies or unclear mocking targets.
- Stay within unit test scope; do not add integration tests.
Example Source files: src/models/User.ts, src/services/AuthService.ts → tests: tests/models/User.spec.ts, tests/services/AuthService.spec.ts