Library › Coding AI › Software developers
Write exactly 3 named Jest tests for a slugify helper
Practice: Setting limits and rules. About 5 minutes.
About this exercise
Write Jest tests for slugify with exactly 3 it blocks inside one describe("slugify"), named exactly 'lowercases and joins words', 'strips accents' and 'throws on empty input'. The cases: "Hello, World!" gives "hello-world", " Crème brûlée " gives "creme-brulee", and "" throws "empty title". The only import is import { slugify } from "../src/slugify.js";. Exactly 1 code block of at most 14 lines, under 20 words of text.
Common mistakes when you ask AI for this
- Too many tests. Asked for tests, the AI writes 8 to 15 of them, including the cases your team deferred. Try: Say: "Exactly 3 it blocks, no other cases."
- Letting the AI name tests. Your team's report groups by test name, and the AI picks its own. Try: Give the names: "'lowercases and joins words', 'strips accents', 'throws on empty input'."
- Not giving the cases. The AI picks its own inputs, which may not match what you agreed to check. Try: List them with expected results, including toThrow("empty title").
- Wrong import style. The AI may use require() or import from a different path. Try: Add: "Only import: import { slugify } from \"../src/slugify.js\";"
What a strong prompt includes
- Sets the number of tests
- Names the tests
- Gives the cases
- Gives the import
- Asks for only code
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)