Engineering Validation Test Generation

Validation Test Prompt

Required fields one at a time, invalid formats, business rules at their exact boundaries — validation tested the way users break it.

Overview

Validation logic accumulates rules until nobody knows what's enforced — and tests that assert "invalid input fails" without saying which rule caught it. This setup generates validation tests for form logic with Jest: required fields tested missing one at a time (each with its own test), invalid formats against the patterns the code claims to enforce, invalid state transitions, and business rule violations at their exact boundaries — plus the edge-case section's six input groups, because validation is where edge cases live.

How to use this resource

  1. One rule, one test

    Required fields missing one at a time — a combined test that fails tells you nothing about which rule broke.

  2. Test the claimed formats

    The email regex, the date pattern, the ID shape — each format the code claims gets a passing and failing case.

  3. Sit on the boundaries

    Business rules tested AT their limits — the 18 in "must be 18+" gets tests at 17, 18, and 19.

Why This Works

  • Rule isolation turns validation failures into one-line diagnoses
  • Format testing catches the regex that enforces less than everyone assumed
  • Boundary placement finds the off-by-one in every age check and quantity limit

Best for

  • Forms whose validation grew rule by rule
  • APIs that validate at the boundary and must say why
  • Teams that found an unenforced "required" field in production

Not for

  • Security-focused input testing (injection) — toggle the Security coverage area or use the auth preset
  • Defining the validation rules — the tests verify what's specified, they don't invent policy

Use cases

  • Testing signup and checkout form validation logic
  • Verifying each required field fails independently
  • Pinning business rules at their numeric boundaries

FAQ

Why does the validation test prompt insist on one required field missing per test?

So a failure names the broken rule. The Validation coverage area specifies "Required fields missing — one at a time, each with its own test," because a combined test that fails tells you nothing about which rule caught it. Paired with output names that "complete the sentence 'it ...'," a red test becomes a one-line diagnosis rather than a hunt.

Does this prompt define my validation rules or just test the ones already in the code?

It tests what's there. TESTING OBJECTIVE says "Generate tests only — do not modify the implementation," and NON-GOALS add "Do not invent requirements — test only specified or clearly implied behavior." It checks formats against "the patterns the code claims to enforce" and business rules at their exact boundaries, listing unresolved behavior under ASSUMPTIONS and GAPS instead of inventing policy.

Which framework conventions does the generated validation test file follow?

Jest. FRAMEWORK GUIDANCE returns one runnable Jest file: mock at the module boundary with jest.mock, reset mocks in beforeEach for independence, test async with async/await and expect(...).resolves/.rejects, and group tests in describe blocks whose names complete "it ...". You still run the file and confirm the assertions in your own suite.

More resources from Test Case Prompt Generator

Resources that pair well

Related tools

Projects that use this resource

Tip: Save time by exploring related resources and tools that integrate with this resource.