Cursor

Verified against Cursor · 2026-06-30

Have Cursor's agent write tests that would actually catch a regression

An agent-mode brief for generating tests against documented behavior rather than the implementation as found, with a forced tripwire that proves each test would actually fail if the behavior broke.

Cursor 2.1

The prompt

Ready to copy — highlighted parts are example details you can swap.

Write tests for lib/pricing/applyDiscount.ts using Vitest with @testing-library conventions. Work in agent mode: read the implementation yourself, but write tests against the expected behavior below — not against whatever the code currently happens to do if the two disagree. Flag any disagreement instead of silently encoding the current behavior as correct.

BEHAVIOR THIS MODULE MUST GUARANTEE
Applies a percentage discount, clamps the result at $0 minimum, and never discounts an already-free item further.

EDGE CASES TO COVER EXPLICITLY
Discount of exactly 100%, discount over 100%, negative price input, discount applied to a $0 item.

RULES
- Every test must fail if the corresponding behavior breaks. Before finishing, pick one test and describe the specific code change that would make it fail, to prove it isn't vacuous.
- Do not mock the function under test itself.
- Do not write a test that only asserts a function was called — assert on its actual output or side effect.
- If two of the edge cases above turn out to be handled by the exact same code path, say so instead of writing two tests that will always pass or fail together.
Customize the highlighted detailsoptional — the prompt above already works

Why this works

Agent mode reads the implementation before writing tests, which creates a specific and well-documented failure mode: it's easy for a model to generate assertions that mirror the current implementation's exact behavior rather than the intended behavior, which lets a test suite pass at 100% while encoding a live bug as 'correct' forever. Separating BEHAVIOR THIS MODULE MUST GUARANTEE from 'go read the implementation' forces a comparison between intent and code instead of a transcription of one into the other, and explicitly asking it to flag disagreement gives it permission to say the code is wrong rather than assume the code is the spec. The 'describe what would make this test fail' step is a concrete tripwire against the single most common form of AI-generated test padding — an assertion that a mock was called, which adds a line of coverage-percentage without adding any actual regression protection, since it would still pass if the real logic were deleted entirely.

What you get back

describe('applyDiscount', () => { it('clamps at $0 minimum even with discount over 100%', () => { expect(applyDiscount(10, 150)).toBe(0) }) // This test fails if the clamp is removed or changed to Math.max(-Infinity, ...) — // verified by temporarily removing the clamp and confirming it returns -5. it('never further discounts an already-free item', () => { expect(applyDiscount(0, 50)).toBe(0) }) }) Flag: edge cases "discount of exactly 100%" and "discount over 100%" both hit the same clamp branch in the current implementation — written as one parameterized test, not two, since they'd always pass or fail together.

Verified against

Cursor 2.1 · 2026-06-30

Changelog

  • 2026-06-30 Initial publish, verified against Cursor 2.1 agent mode with Vitest.

Need this built into your business?

If a prompt isn't enough — custom software, built and maintained for you — that's Scult's day job.

EXPLORE CUSTOM SOFTWARE
All Cursor prompts

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY