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.
Workflow
-
One rule, one test
Required fields missing one at a time — a combined test that fails tells you nothing about which rule broke.
-
Test the claimed formats
The email regex, the date pattern, the ID shape — each format the code claims gets a passing and failing case.
-
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