deno.land / x / zod@v3.19.1 / __tests__ / safeparse.test.ts

safeparse.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
// @ts-ignore TS6133import { expect } from "https://deno.land/x/expect@v0.2.6/mod.ts";const test = Deno.test;
import * as z from "../index.ts";const stringSchema = z.string();
test("safeparse fail", () => { const safe = stringSchema.safeParse(12); expect(safe.success).toEqual(false); expect((safe as any).error).toBeInstanceOf(z.ZodError);});
test("safeparse pass", () => { const safe = stringSchema.safeParse("12"); expect(safe.success).toEqual(true); expect((safe as any).data).toEqual("12");});
test("safeparse unexpected error", () => { expect(() => stringSchema .refine((data) => { throw new Error(data); }) .safeParse("12") ).toThrow();});
zod

Version Info

Tagged at
a year ago