-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
pipeline.test.ts
30 lines (26 loc) · 880 Bytes
/
pipeline.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
// @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("string to number pipeline", () => {
const schema = z.string().transform(Number).pipe(z.number());
expect(schema.parse("1234")).toEqual(1234);
});
test("string to number pipeline async", async () => {
const schema = z
.string()
.transform(async (val) => Number(val))
.pipe(z.number());
expect(await schema.parseAsync("1234")).toEqual(1234);
});
test("break if dirty", () => {
const schema = z
.string()
.refine((c) => c === "1234")
.transform(async (val) => Number(val))
.pipe(z.number().refine((v) => v < 100));
const r1: any = schema.safeParse("12345");
expect(r1.error.issues.length).toBe(1);
const r2: any = schema.safeParse("3");
expect(r2.error.issues.length).toBe(1);
});