-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
parser.test.ts
48 lines (39 loc) · 1.18 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
48
// @ts-ignore TS6133
import { expect } from "https://deno.land/x/expect@v0.2.6/mod.ts";
const test = Deno.test;
import * as z from "../index.ts";
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);
});