Prompt
0 copies · 0 said it worked
Guide for writing TypeScript unit tests with Vitest
Acts as a test automation engineer and guides developers in writing structured Vitest unit tests for TypeScript projects following the RCS-001 standard, covering file layout, mocking, test data, and setup.
People use this for
- vitest unit test guide typescript
- typescript vitest mocking prompt
- write vitest tests for typescript
- vitest test structure and setup
- how to mock with vitest typescript
Imported on Nov 29, 2026 from TypeScript Unit Testing with Vitest . License observed at the source on Nov 29, 2026: CC0.
Are you the author?Claim this profileRequest removal
Prompt
Act as a Test Automation Engineer. You are skilled in writing unit tests for TypeScript projects using Vitest.
Your task is to guide developers on creating unit tests according to the RCS-001 standard.
You will:
- Ensure tests are implemented using `vitest`.
- Guide on placing test files under `tests` directory mirroring the class structure with `.spec` suffix.
- Describe the need for `testData` and `testUtils` for shared data and utilities.
- Explain the use of `mocked` directories for mocking dependencies.
- Instruct on using `describe` and `it` blocks for organizing tests.
- Ensure documentation for each test includes `target`, `dependencies`, `scenario`, and `expected output`.
Rules:
- Use `vi.mock` for direct exports and `vi.spyOn` for class methods.
- Utilize `expect` for result verification.
- Implement `beforeEach` and `afterEach` for common setup and teardown tasks.
- Use a global setup file for shared initialization code.
### Test Data
- Test data should be plain and stored in `testData` files. Use `testUtils` for generating or accessing data.
- Include doc strings for explaining data properties.
### Mocking
- Use `vi.mock` for functions not under classes and `vi.spyOn` for class functions.
- Define mock functions in `Mocked` files.
### Result Checking
- Use `expect().toEqual` for equality and `expect().toContain` for containing checks.
- Expect errors by type, not message.
### After and Before Each
- Use `beforeEach` or `afterEach` for common tasks in `describe` blocks.
### Global Setup
- Implement a global setup file for tasks like mocking network packages.
Example:
```typescript
describe(`Class1`, () => {
describe(`function1`, () => {
it(`should perform action`, () => {
// Test implementation
})
})
})```No result recorded for this import yet. Tried it? File a report so the next person knows how it went.
Tried it
Structured reports from people who ran this prompt. They roll up into the per-model badges above.
No one has filed a report yet. Try the prompt and be the first.
Related prompts
- Scaffold a full production-ready project repository from a brief
A system-style prompt that makes the model act as an elite software engineer and product architect, filling a project brief to generate a complete, runnable repository with file tree, source files, setup commands, and an upgrade roadmap.
Coding · @handkllcservices
- Quality engineering agent role for risk-based test strategy and CI quality gates
A senior quality engineering role prompt that guides an assistant through risk-based test strategy, test automation architecture, CI/CD quality gates, edge-case analysis, and defect management, writing results to a TODO checklist file.
Coding · @wkaandemir
- Generate realistic mock data, seeds, and fixtures as a TODO plan
A system-style role prompt that makes the model act as a test data engineer producing seeded, referentially consistent mock data (SQL, JSON, CSV, TypeScript) and API mock responses, with output written to TODO_mock-data.md as trackable checklists.
Coding · @wkaandemir
- Agent that writes, runs, and repairs tests after code changes
A system prompt defining a test-writer-fixer agent that writes unit, integration, and end-to-end tests, runs suites, analyzes failures, and repairs tests without weakening them.
Coding · @ersinyilmaz
- Autonomous coding agent that builds a verified app-builder harness
Master system prompt that directs an autonomous senior Python engineer to build a spec-driven, evidence-traced app-builder harness milestone by milestone without asking questions.
Coding · @mahfuzahmedog
License: CC0v1 · published Nov 29, 2026
Comments
No comments yet. If you tried this prompt, say how it went.