← Back to Library|PromptsWrite Unit Tests for a Function

Write Unit Tests for a Function

Generate comprehensive unit tests that cover happy paths, edge cases, and error scenarios for any function.

5-10 min|Intermediate
BuildQuick WinDeveloper
Prompt Template
Look at my project's test setup (check package.json for the test runner and any existing test files for conventions).

Write unit tests for this function:

[paste the function code]

Write tests for:
1. Happy path (expected inputs produce expected outputs)
2. Edge cases: [list specific edge cases, e.g. empty array, null input, max integer, special characters]
3. Error cases: [list what should throw or return errors]
4. Boundary conditions: [e.g. exactly at limit, one over limit]

Use descriptive test names that explain the expected behavior, not the implementation. Group related tests with describe blocks. Do NOT mock anything unless I specify which dependencies to mock."

**Output format:** Complete test file ready to run.

Explicitly listing edge cases and error scenarios prevents the AI from writing tests that only cover the obvious happy path.

After writing any function with business logic. Skip for trivial getters/setters.

Write Unit Tests for a Function | Library | Modern Vibe Coding