forked from colinhacks/zod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.test.ts
47 lines (38 loc) · 1.13 KB
/
parser.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// @ts-ignore TS6133
import { expect, test } from "@jest/globals";
import * as z from "../index";
test("parse strict object with unknown keys", () => {
expect(() =>
z
.object({ name: z.string() })
.strict()
.parse({ name: "bill", unknownKey: 12 } as any)
).toThrow();
});
test("parse nonstrict object with unknown keys", () => {
z.object({ name: z.string() })
.nonstrict()
.parse({ name: "bill", unknownKey: 12 });
});
test("invalid left side of intersection", () => {
expect(() =>
z.intersection(z.string(), z.number()).parse(12 as any)
).toThrow();
});
test("invalid right side of intersection", () => {
expect(() =>
z.intersection(z.string(), z.number()).parse("12" as any)
).toThrow();
});
test("parsing non-array in tuple schema", () => {
expect(() => z.tuple([]).parse("12" as any)).toThrow();
});
test("incorrect num elements in tuple", () => {
expect(() => z.tuple([]).parse(["asdf"] as any)).toThrow();
});
test("invalid enum value", () => {
expect(() => z.enum(["Blue"]).parse("Red" as any)).toThrow();
});
test("parsing unknown", () => {
z.string().parse("Red" as unknown);
});