CoreMesh

Write Unit Tests for a Function

Models love testing the happy path. This prompt starts from the edge cases you know about, then fills in the normal ones, in the framework you already use.

Works with Claude, ChatGPT and Gemini3 fields

prompt.md · 513 charslive
Write unit tests in TypeScript + Vitest for this function:

```
export function slugify(s: string): string {
  return s.toLowerCase().trim().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
}
```

Start with edge cases (emoji, accents, empty string, only symbols), then the normal cases.
Rules: one behaviour per test, descriptive test names, no mocking unless the function has side effects.
If a test would fail with the current code, mark it and explain why in one line instead of changing the expected value.

Everything you type stays in your browser. Remove passwords, keys and personal data before pasting anything into an AI tool.

Why this prompt is written this way

  • Edge cases first. Listing the cases you worry about makes sure they are covered before the obvious ones.
  • One behaviour per test. Small tests tell you exactly what broke when they fail.
  • Mark failing tests. If the code has a bug, you want the test to show it, not to be bent around it.

Example answer

Illustrative and shortened, to show the shape of a good answer. Real answers vary by model.

it('returns empty string for empty input', ...)
it('drops emoji', ...)
it('keeps accented letters as plain letters (fails today: they become dashes)', ...)
it('joins words with single dashes', ...)

Tips

  • Paste any helper the function calls, or the model will guess its behaviour.
  • Run the tests and paste failures back into the chat.

How to use it

  1. Replace the example values with your own. The prompt on the right updates as you type.
  2. Press Copy prompt and paste it into any AI chat, or open it straight in Claude or ChatGPT.
  3. Save it as prompt.md if you want to reuse it.
Claude ↗

New notes, no spam.

One post at a time, only when there's something worth reading. Follow in any feed reader.

Subscribe via RSS