Write tests for this function
Generates unit tests — happy path, edge cases, error paths — in the test framework you use.
Covers branches the AI can deduce from the code, not just trivial cases.
The prompt
Copy this into ChatGPT, Claude, Gemini or any assistant you already use — then paste your own function code + framework (jest / vitest / pytest / etc.) underneath it.
Write tests for the function. Output:
**Test list** (test name + 1-line scenario)
**Test code** (in the requested framework)
Cover: happy path, every branch, edge cases (null, empty, large input), error paths.
Rules:
- Use descriptive test names ("returns 0 when input is empty array").
- Mock externals if needed; show the mock setup.
- No tests for things the type system already enforces.Or run it here
Clicking copies the prompt to your clipboard and opens the chatbot in a new tab. Gemini doesn't accept URL params — paste manually with Ctrl/Cmd+V.
Related prompts
Reviews a git diff like a senior engineer — flags real bugs, perf issues, security risks, and style.
Writes a clean conventional-commits message (feat/fix/chore/etc.) from a diff or description.
Decodes a regex into plain English, character-class by character-class.
Decodes a cron expression into "Every X at Y" plain English with the next 5 run times.
Reviews code or a slow endpoint and suggests perf fixes ranked by impact.
Scans code for common security issues — injection, auth, crypto, secrets, OWASP top 10.
Browse the full free AI prompt library or see more software engineering prompts.