/
home
/
techb158
/
balavpn.abdallabala.com
/
node_modules
/
zod
/
src
/
v4
/
classic
/
tests
/
/home/techb158/balavpn.abdallabala.com/node_modules/zod/src/v4/classic/tests
mkdir
upload
Name
Size
Mode
Actions
anyunknown.test.ts
639
0666
edit
dl
rm
array.test.ts
7284
0666
edit
dl
rm
assignability.test.ts
6790
0666
edit
dl
rm
async-parsing.test.ts
12311
0666
edit
dl
rm
async-refinements.test.ts
1867
0666
edit
dl
rm
base.test.ts
179
0666
edit
dl
rm
bigint.test.ts
1956
0666
edit
dl
rm
brand.test.ts
2206
0666
edit
dl
rm
catch.test.ts
7224
0666
edit
dl
rm
coalesce.test.ts
743
0666
edit
dl
rm
coerce.test.ts
7736
0666
edit
dl
rm
continuability.test.ts
7478
0666
edit
dl
rm
custom.test.ts
1215
0666
edit
dl
rm
date.test.ts
962
0666
edit
dl
rm
datetime.test.ts
11511
0666
edit
dl
rm
default.test.ts
7717
0666
edit
dl
rm
description.test.ts
1294
0666
edit
dl
rm
discriminated-unions.test.ts
16810
0666
edit
dl
rm
enum.test.ts
8488
0666
edit
dl
rm
error-utils.test.ts
12572
0666
edit
dl
rm
error.test.ts
19502
0666
edit
dl
rm
file.test.ts
2460
0666
edit
dl
rm
firstparty.test.ts
2977
0666
edit
dl
rm
function.test.ts
6299
0666
edit
dl
rm
generics.test.ts
2162
0666
edit
dl
rm
index.test.ts
27562
0666
edit
dl
rm
instanceof.test.ts
1052
0666
edit
dl
rm
intersection.test.ts
4763
0666
edit
dl
rm
json.test.ts
3309
0666
edit
dl
rm
lazy.test.ts
4756
0666
edit
dl
rm
literal.test.ts
2478
0666
edit
dl
rm
map.test.ts
4817
0666
edit
dl
rm
nan.test.ts
645
0666
edit
dl
rm
nested-refine.test.ts
3623
0666
edit
dl
rm
nonoptional.test.ts
2405
0666
edit
dl
rm
nullable.test.ts
591
0666
edit
dl
rm
number.test.ts
7827
0666
edit
dl
rm
object.test.ts
15999
0666
edit
dl
rm
optional.test.ts
4130
0666
edit
dl
rm
partial.test.ts
4835
0666
edit
dl
rm
pickomit.test.ts
4422
0666
edit
dl
rm
pipe.test.ts
1848
0666
edit
dl
rm
prefault.test.ts
1007
0666
edit
dl
rm
preprocess.test.ts
6959
0666
edit
dl
rm
primitive.test.ts
7649
0666
edit
dl
rm
promise.test.ts
2315
0666
edit
dl
rm
prototypes.test.ts
498
0666
edit
dl
rm
readonly.test.ts
11777
0666
edit
dl
rm
record.test.ts
8118
0666
edit
dl
rm
recursive-types.test.ts
7335
0666
edit
dl
rm
refine.test.ts
14774
0666
edit
dl
rm
registries.test.ts
5999
0666
edit
dl
rm
set.test.ts
5572
0666
edit
dl
rm
standard-schema.test.ts
1369
0666
edit
dl
rm
string-formats.test.ts
3068
0666
edit
dl
rm
string.test.ts
64124
0666
edit
dl
rm
stringbool.test.ts
2333
0666
edit
dl
rm
template-literal.test.ts
34836
0666
edit
dl
rm
to-json-schema.test.ts
59276
0666
edit
dl
rm
transform.test.ts
6000
0666
edit
dl
rm
tuple.test.ts
4702
0666
edit
dl
rm
union.test.ts
2497
0666
edit
dl
rm
validations.test.ts
6736
0666
edit
dl
rm
void.test.ts
306
0666
edit
dl
rm
Edit:
/home/techb158/balavpn.abdallabala.com/node_modules/zod/src/v4/classic/tests/function.test.ts
(6299B)
import { expect, expectTypeOf, test } from "vitest"; import * as z from "zod/v4"; const args1 = z.tuple([z.string()]); const returns1 = z.number(); const func1 = z.function({ input: args1, output: returns1, }); test("function parsing", () => { const parsed = func1.implement((arg: any) => arg.length); const result = parsed("asdf"); expect(result).toBe(4); }); test("parsed function fail 1", () => { // @ts-expect-error const parsed = func1.implement((x: string) => x); expect(() => parsed("asdf")).toThrow(); }); test("parsed function fail 2", () => { // @ts-expect-error const parsed = func1.implement((x: string) => x); expect(() => parsed(13 as any)).toThrow(); }); test("function inference 1", () => { type func1 = (typeof func1)["_input"]; expectTypeOf<func1>().toEqualTypeOf<(k: string) => number>(); }); // test("method parsing", () => { // const methodObject = z.object({ // property: z.number(), // method: z // .function() // .input(z.tuple([z.string()])) // .output(z.number()), // }); // const methodInstance = { // property: 3, // method: function (s: string) { // return s.length + this.property; // }, // }; // const parsed = methodObject.parse(methodInstance); // expect(parsed.method("length=8")).toBe(11); // 8 length + 3 property // }); // test("async method parsing", async () => { // const methodObject = z.object({ // property: z.number(), // method: z.function().input(z.string()).output(z.promise(z.number())), // }); // const methodInstance = { // property: 3, // method: async function (s: string) { // return s.length + this.property; // }, // }; // const parsed = methodObject.parse(methodInstance); // expect(await parsed.method("length=8")).toBe(11); // 8 length + 3 property // }); test("args method", () => { const t1 = z.function(); type t1 = (typeof t1)["_input"]; expectTypeOf<t1>().toEqualTypeOf<(...args_1: never[]) => unknown>(); t1._input; const t2args = z.tuple([z.string()], z.unknown()); const t2 = t1.input(t2args); type t2 = (typeof t2)["_input"]; expectTypeOf<t2>().toEqualTypeOf<(arg: string, ...args_1: unknown[]) => unknown>(); const t3 = t2.output(z.boolean()); type t3 = (typeof t3)["_input"]; expectTypeOf<t3>().toEqualTypeOf<(arg: string, ...args_1: unknown[]) => boolean>(); }); // test("custom args", () => { // const fn = z.function().implement((_a: string, _b: number) => { // return new Date(); // }); // expectTypeOf(fn).toEqualTypeOf<(a: string, b: number) => Date>(); // }); const args2 = z.tuple([ z.object({ f1: z.number(), f2: z.string().nullable(), f3: z.array(z.boolean().optional()).optional(), }), ]); const returns2 = z.union([z.string(), z.number()]); const func2 = z.function({ input: args2, output: returns2, }); test("function inference 2", () => { type func2 = (typeof func2)["_input"]; expectTypeOf<func2>().toEqualTypeOf< (arg: { f3?: (boolean | undefined)[] | undefined; f1: number; f2: string | null; }) => string | number >(); }); test("valid function run", () => { const validFunc2Instance = func2.implement((_x) => { _x.f2; _x.f3![0]; return "adf" as any; }); validFunc2Instance({ f1: 21, f2: "asdf", f3: [true, false], }); }); test("input validation error", () => { const schema = z.function({ input: z.tuple([z.string()]), output: z.void(), }); const fn = schema.implement(() => 1234 as any); // @ts-expect-error const checker = () => fn(); try { checker(); } catch (e: any) { expect(e.issues).toMatchInlineSnapshot(` [ { "code": "invalid_type", "expected": "string", "message": "Invalid input: expected string, received undefined", "path": [ 0, ], }, ] `); } }); test("array inputs", () => { const a = z.function({ input: [ z.object({ name: z.string(), age: z.number().int(), }), ], output: z.string(), }); a.implement((args) => { return `${args.age}`; }); const b = z.function({ input: [ z.object({ name: z.string(), age: z.number().int(), }), ], }); b.implement((args) => { return `${args.age}`; }); }); test("output validation error", () => { const schema = z.function({ input: z.tuple([]), output: z.string(), }); const fn = schema.implement(() => 1234 as any); try { fn(); } catch (e: any) { expect(e.issues).toMatchInlineSnapshot(` [ { "code": "invalid_type", "expected": "string", "message": "Invalid input: expected string, received number", "path": [], }, ] `); } }); test("function with async refinements", async () => { const schema = z .function() .input([z.string().refine(async (val) => val.length > 10)]) .output(z.promise(z.number().refine(async (val) => val > 10))); const func = schema.implementAsync(async (val) => { return val.length; }); const results = []; try { await func("asdfasdf"); results.push("success"); } catch (_) { results.push("fail"); } try { await func("asdflkjasdflkjsf"); results.push("success"); } catch (_) { results.push("fail"); } expect(results).toEqual(["fail", "success"]); }); test("non async function with async refinements should fail", async () => { const func = z .function() .input([z.string().refine(async (val) => val.length > 10)]) .output(z.number().refine(async (val) => val > 10)) .implement((val) => { return val.length; }); const results = []; try { await func("asdasdfasdffasdf"); results.push("success"); } catch (_) { results.push("fail"); } expect(results).toEqual(["fail"]); }); test("extra parameters with rest", () => { const maxLength5 = z .function() .input([z.string()], z.unknown()) .output(z.boolean()) .implement((str, _arg, _qewr) => { return str.length <= 5; }); const filteredList = ["apple", "orange", "pear", "banana", "strawberry"].filter(maxLength5); expect(filteredList.length).toEqual(2); });
Save
cmd:
run