Generate Tests
Generate Tests for a Module
Add tests that match the repo's runner and style, covering the behaviour that would actually break users.
The Prompt
generate-tests-for-a-module.md
Add tests for this module using the test stack already in the repo. Module / files: {{module}} Behaviour that must not regress: {{behaviour}} Known edge cases: {{edges}} Rules: - Mirror existing test file placement and naming - Prefer behaviour over implementation details - Include the unhappy paths in {{edges}} - Do not mock so much that the test asserts nothing - If a case needs a fixture, create a small one next to existing fixtures End with: how to run only these tests, and any behaviour you could not cover because the code is untestable - with a minimal seam if needed.
Negative prompt
Included when you copy the prompt
Do not invent a different test runner or folder layout than the repo uses. Do not mock so heavily that assertions prove nothing about real behaviour. Do not skip the unhappy paths in {{edges}}. Do not assert on private internals or snapshot unrelated UI chrome. Do not add huge fixtures when a small one beside existing fixtures will do. Do not leave the user without a command to run only these tests.
Fill in your details below - this prompt updates as you type, then copy it.
Fill in your details
0 of 3 filled. Preview updates as you type - then copy the finished prompt (negative prompt included when present).
generate-tests-for-a-module.md
Prompt preview
Add tests for this module using the test stack already in the repo. Module / files: {{module}} Behaviour that must not regress: {{behaviour}} Known edge cases: {{edges}} Rules: - Mirror existing test file placement and naming - Prefer behaviour over implementation details - Include the unhappy paths in {{edges}} - Do not mock so much that the test asserts nothing - If a case needs a fixture, create a small one next to existing fixtures End with: how to run only these tests, and any behaviour you could not cover because the code is untestable - with a minimal seam if needed.
Examples
Example input
Module: src/lib/slugify.ts Behaviour: Turn titles into URL slugs; collapse spaces; strip punctuation; lowercase. Edges: empty string → ""; unicode letters; multiple hyphens collapsed; trailing hyphen trimmed.
What you should get
Added src/lib/slugify.test.ts next to existing *.test.ts files (Vitest). Cases: "Hello World" → "hello-world"; "" → ""; "API & Docs!" → "api-docs"; "äö" kept or folded per current impl; "--a--" → "a". No mocks (pure function). Run: npx vitest run src/lib/slugify.test.ts Untestable: none. If locale-specific folding is added later, inject a normalizer seam.
When to use this prompt
Use it when
- You need help with engineers.
- You need help with agent users.
Skip it when
- You only need a one-line ask with no constraints, format, or context.
- You cannot supply the fill-in details the template asks for.
- A different category or tool-specific workflow fits the job better.
How to get a good result
Done when
Added src/lib/slugify.test.ts next to existing *.test.ts files (Vitest). Cases: "Hello World" → "hello-world"; "" → ""; "API & Docs!" → "api-docs"; "äö" kept or folded per current impl; "--a--" → "a". No mocks (pure function). Run: npx vitest run src/lib/slugify.test.ts Untestable: none. If locale-specific folding is added later, inject a normalizer seam.
Common mistakes
- Leaving module, behaviour, edges vague - the model then invents placeholders.
- Asking Cursor, ChatGPT, or Claude for a shorter answer after a long structured prompt - that throws away the format rules.
- Stopping when the first draft appears instead of checking it against the success criteria below.
FAQ
- What do I fill in before I copy this prompt?
- Replace these placeholders with your details: module, behaviour, edges. Required fields are marked on the page. The prompt text updates as you type.
- Which AI tools is this prompt written for?
- It works best with Cursor, ChatGPT, Claude. Copy the filled prompt and paste it into the tool you already use.
- What should a good result look like?
- Added src/lib/slugify.test.ts next to existing *.test.ts files (Vitest). Cases: "Hello World" → "hello-world"; "" → ""; "API & Docs!" → "api-docs"; "äö" kept or folded per current impl; "--a--" → "a". No mocks (pure function). Run: npx vitest run src/lib/slugify.test.ts Untestable: none. If locale-specific folding is added later, inject a normalizer seam.
- What are common mistakes with this prompt?
- Leaving module, behaviour, edges vague - the model then invents placeholders. Asking Cursor, ChatGPT, or Claude for a shorter answer after a long structured prompt - that throws away the format rules. Stopping when the first draft appears instead of checking it against the success criteria below.
Best for
- Engineers
- Agent users
Related Prompts
More prompts like this — same topic and style.


