Write unit tests for a function prompt template
Generate a thorough unit test suite for a single function, covering the happy path, edge cases, and failure modes using your chosen test framework.
Free to copy3 fill-in variablesWorks with any text-based AI model
Copy the prompt
Keep the instruction intact and replace each double-braced field with your own context.
Write unit tests for a function
Write unit tests for the following {{language}} function using {{framework}}.
Function:
```{{language}}
{{code}}
```
Requirements:
- Cover the happy path with representative inputs.
- Cover edge cases: empty, zero, negative, boundary, and very large values where
they apply.
- Cover failure modes: invalid input, thrown errors, and unexpected types.
- Use clear, behaviour-describing test names (e.g. "returns 0 for an empty list").
- Arrange each test with minimal setup and assert one behaviour per test.
- If the function has external dependencies, show how to mock or stub them.
Before writing the tests, list the distinct behaviours you intend to cover as a
short bullet list, then output the complete, runnable test file. Flag any input I
should clarify if the intended behaviour is ambiguous.
Fill in the variables
Use the examples as a shape, not as required wording.
{{language}}- Language the function is written inExample: JavaScript
{{framework}}- Test framework and runner to targetExample: Vitest
{{code}}- The function to test, including its signatureExample: export function slugify(s) { return s.trim().toLowerCase().replace(/\s+/g, '-'); }
Filled-in example
This shows the template with realistic inputs before it is sent to a model.
Write unit tests for the following JavaScript function using Vitest.
Function:
```javascript
export function slugify(s) {
return s.trim().toLowerCase().replace(/\s+/g, '-');
}
```
Cover the happy path, edge cases (empty string, extra whitespace, mixed case),
and failure modes (non-string input). List the behaviours first, then output the
complete runnable test file.
How to use this template
Three checks keep the result useful and grounded in your actual task.
- Give it real context.Replace every variable and remove any instruction that does not apply.
- Run it in your preferred model.The template is plain text, so it works with ChatGPT, Claude, Gemini, and local models.
- Review before you rely on it.Check facts, code, claims, and sensitive information; then save the wording that performed best.