Write the tests AI forgets

Skill
Testing with AI
Time
About 25 min
Access
Free

parseDuration turns strings like "1h 30m" into minutes. It’s used for a time-tracking form, so users will type all sorts of things into it.

Ask an AI to write tests for it. Then look hard at what it gave you: AI-written tests usually cover the happy path and miss the edges. Add the tests it missed.

Use any test runner (Jest, Vitest, or Node’s built-in node:test).

Think about

  • Every valid format the function accepts
  • Boundaries (what happens at 59 and 60 minutes?)
  • Input that should be rejected, and how it’s rejected
  • Places where you’re not sure what the function should do

Submit

  • Your full test file
  • Which tests you added yourself after reviewing the AI’s version, and why
  • Anything about the function’s behaviour you think is a bug or needs a product decision
parse-duration.js
// parse-duration.js// Converts strings like "1h 30m", "45m" or "2h" into minutes.function parseDuration(input) {  if (typeof input !== 'string') {    throw new TypeError('input must be a string');  }  const match = input.trim().match(/^(?:(\d+)h)?\s*(?:(\d+)m)?$/i);  if (!match || (!match[1] && !match[2])) {    throw new Error(`Invalid duration: ${input}`);  }  const hours = Number(match[1] ?? 0);  const minutes = Number(match[2] ?? 0);  if (minutes >= 60) {    throw new Error('Minutes must be under 60');  }  return hours * 60 + minutes;} module.exports = { parseDuration };

Your submission

Do the work in your own editor with any AI tool, then paste it here. Resubmit as often as you like. Your submission is sent to OpenAI to write the review, so leave out passwords and API keys.

Paste your main prompts, or describe what you asked and what you checked yourself. The review comments on this too.