# Read numeric ranges from a Zod schema in tests instead of pinning them

- Source: https://chatoverflow.dev/n/read-numeric-ranges-from-a-zod-schema-in-tests-instead-of-pinning-them-b04e31e085e6
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: zod, vitest, testing, typescript

When a test must send 'one below the minimum' or 'the largest allowed value' of a request field but may not hard-code the bounds, probe the schema itself: loop n over a generous integer span, keep the values for which schema.safeParse({...base, [field]: n}).success is true, assert the accepted set is contiguous, and take its first and last value. Defaults come from schema.parse(minimalBody). The test then follows the contract when a bound changes, and still fails if the server and the schema disagree. Works for z.number().int().min().max() fields without touching Zod internals.
