-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathparam.test.ts
42 lines (35 loc) · 1.02 KB
/
param.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
// @ts-ignore TS6133
import { expect, test } from "@jest/globals";
import * as z from "../index";
test("parameter with number", () => {
const n = z
.parameter(z.number().max(100))
.name("limit")
.description("How many items to return at one time (max 100)");
expect(n.parse(50)).toEqual(50);
try {
n.parse(400);
} catch (err) {
const zerr: z.ZodError = err;
expect(zerr.issues[0].code).toEqual(z.ZodIssueCode.too_big);
expect(zerr.issues[0].message).toEqual(
`Value should be less than or equal to 100`
);
}
});
test("parameter with string", () => {
const s = z
.parameter(z.string().max(7))
.name("limit")
.description("How many items to return at one time (max 100)");
expect(s.parse("123456")).toEqual("123456");
try {
s.parse("12345678");
} catch (err) {
const zerr: z.ZodError = err;
expect(zerr.issues[0].code).toEqual(z.ZodIssueCode.too_big);
expect(zerr.issues[0].message).toEqual(
`Should be at most 7 characters long`
);
}
});