PromptDev
Write unit tests for code
Get tests that earn their place: behavior-driven cases, edge cases named before they're coded, and no tests that merely restate the implementation.
Last updated
Fill in the blanks
Assembled in your browser — nothing you type is stored or sent anywhere.
Your prompt
Write unit tests for the code below using Vitest.
Before writing any test, list the behaviours worth testing — normal cases, edge cases (empty input, boundaries, invalid types), and error paths — then implement each as one focused test with a name that states the expected behaviour. Test the public behaviour, not the implementation details: no asserting on internal calls unless a side effect IS the contract. If a behaviour is ambiguous from the code alone, write the test name and mark it with a TODO comment asking me, instead of guessing the intent.
Extra attention to: what happens with an empty array and with duplicate keys
Code:
[paste the function or module here]
Model-agnostic — works in Claude, ChatGPT, Gemini or any AI chat.
Why this prompt works
- →Listing behaviours before writing tests is what stops the default failure: three near-identical happy-path tests and no edge cases.
- →"Public behaviour, not implementation" keeps the tests alive through refactors — tests coupled to internals fail when code improves, and teams learn to delete them.
- →The TODO-instead-of-guessing rule surfaces ambiguity as a question to you, rather than silently baking one interpretation into the test suite.