MCPcopy
hub / github.com/colinhacks/zod / checkErrors

Function checkErrors

packages/zod/src/v3/tests/optional.test.ts:6–18  ·  view source on GitHub ↗
(a: z.ZodTypeAny, bad: any)

Source from the content-addressed store, hash-verified

4import * as z from "zod/v3";
5
6function checkErrors(a: z.ZodTypeAny, bad: any) {
7 let expected: any;
8 try {
9 a.parse(bad);
10 } catch (error) {
11 expected = (error as z.ZodError).formErrors;
12 }
13 try {
14 a.optional().parse(bad);
15 } catch (error) {
16 expect((error as z.ZodError).formErrors).toEqual(expected);
17 }
18}
19
20test("Should have error messages appropriate for the underlying type", () => {
21 checkErrors(z.string().min(2), 1);

Callers 1

optional.test.tsFile · 0.70

Calls 2

optionalMethod · 0.80
parseMethod · 0.65

Tested by

no test coverage detected