Const
import * as fc from 'fast-check'
import { z } from 'zod'
import { zxTest } from '@traversable/zod-test'
const [seed] = fc.sample(zxTest.SeedInvalidDataGenerator, 1)
const ZodSchema = zxTest.seedToSchema(seed)
const dataset = fc.sample(zxTest.seedToInvalidData(seed), 5)
const results = dataset.map((pt) => ZodSchema.safeParse(pt).success)
console.log(results) // => [false, false, false, false, false]
zxTest.SeedInvalidDataGenerator
A seed generator that can be interpreted to produce reliably invalid data.
This was originally developed to test for parity between various schema libraries.
To use it, you'll need to have fast-check installed.
Note that certain schemas make generating invalid data impossible (like z.any
z.any
) or prohibitively difficult (like z.catchz.catch
). For this reason, those schemas are not seeded.To see the list of excluded schemas, see seedsThatPreventGeneratingInvalidData
zxTest.seedsThatPreventGeneratingInvalidData
.See also:
zxTest.SeedValidDataGenerator