/home/techb158/balavpn.abdallabala.com/node_modules/zod/src/v4/classic/tests
NameSizeModeActions
anyunknown.test.ts6390666editdlrm
array.test.ts72840666editdlrm
assignability.test.ts67900666editdlrm
async-parsing.test.ts123110666editdlrm
async-refinements.test.ts18670666editdlrm
base.test.ts1790666editdlrm
bigint.test.ts19560666editdlrm
brand.test.ts22060666editdlrm
catch.test.ts72240666editdlrm
coalesce.test.ts7430666editdlrm
coerce.test.ts77360666editdlrm
continuability.test.ts74780666editdlrm
custom.test.ts12150666editdlrm
date.test.ts9620666editdlrm
datetime.test.ts115110666editdlrm
default.test.ts77170666editdlrm
description.test.ts12940666editdlrm
discriminated-unions.test.ts168100666editdlrm
enum.test.ts84880666editdlrm
error-utils.test.ts125720666editdlrm
error.test.ts195020666editdlrm
file.test.ts24600666editdlrm
firstparty.test.ts29770666editdlrm
function.test.ts62990666editdlrm
generics.test.ts21620666editdlrm
index.test.ts275620666editdlrm
instanceof.test.ts10520666editdlrm
intersection.test.ts47630666editdlrm
json.test.ts33090666editdlrm
lazy.test.ts47560666editdlrm
literal.test.ts24780666editdlrm
map.test.ts48170666editdlrm
nan.test.ts6450666editdlrm
nested-refine.test.ts36230666editdlrm
nonoptional.test.ts24050666editdlrm
nullable.test.ts5910666editdlrm
number.test.ts78270666editdlrm
object.test.ts159990666editdlrm
optional.test.ts41300666editdlrm
partial.test.ts48350666editdlrm
pickomit.test.ts44220666editdlrm
pipe.test.ts18480666editdlrm
prefault.test.ts10070666editdlrm
preprocess.test.ts69590666editdlrm
primitive.test.ts76490666editdlrm
promise.test.ts23150666editdlrm
prototypes.test.ts4980666editdlrm
readonly.test.ts117770666editdlrm
record.test.ts81180666editdlrm
recursive-types.test.ts73350666editdlrm
refine.test.ts147740666editdlrm
registries.test.ts59990666editdlrm
set.test.ts55720666editdlrm
standard-schema.test.ts13690666editdlrm
string-formats.test.ts30680666editdlrm
string.test.ts641240666editdlrm
stringbool.test.ts23330666editdlrm
template-literal.test.ts348360666editdlrm
to-json-schema.test.ts592760666editdlrm
transform.test.ts60000666editdlrm
tuple.test.ts47020666editdlrm
union.test.ts24970666editdlrm
validations.test.ts67360666editdlrm
void.test.ts3060666editdlrm
Edit: /home/techb158/balavpn.abdallabala.com/node_modules/zod/src/v4/classic/tests/registries.test.ts (5999B)
import { expect, expectTypeOf, test } from "vitest"; import * as z from "zod/v4"; test("globalRegistry", () => { const reg = z.registry(); const a = z.string(); reg.add(a); expect(reg.has(a)).toEqual(true); reg.remove(a); expect(reg.has(a)).toEqual(false); a.register(z.globalRegistry, { field: "sup" }); expect(z.globalRegistry.has(a)).toEqual(true); expect(z.globalRegistry.get(a)).toEqual({ field: "sup" }); z.globalRegistry.remove(a); expect(z.globalRegistry.has(a)).toEqual(false); }); test("z.registry", () => { const fieldRegistry = z.registry<{ name: string; description: string }>(); const a = z.string(); fieldRegistry.add(a, { name: "hello", description: "world" }); const a_meta = fieldRegistry.get(a); expect(a_meta).toEqual({ name: "hello", description: "world" }); fieldRegistry.remove(a); expect(fieldRegistry.has(a)).toEqual(false); expect(fieldRegistry.get(a)).toEqual(undefined); }); test("z.registry no metadata", () => { const fieldRegistry = z.registry(); const a = z.string(); fieldRegistry.add(a); fieldRegistry.add(z.number()); expect(fieldRegistry.get(a)).toEqual(undefined); expect(fieldRegistry.has(a)).toEqual(true); }); test("z.registry with schema constraints", () => { const fieldRegistry = z.registry<{ name: string; description: string }, z.ZodString>(); const a = z.string(); fieldRegistry.add(a, { name: "hello", description: "world" }); // @ts-expect-error fieldRegistry.add(z.number(), { name: "test" }); // @ts-expect-error z.number().register(fieldRegistry, { name: "test", description: "test" }); }); // test("z.namedRegistry", () => { // const namedReg = z // .namedRegistry<{ name: string; description: string }>() // .add(z.string(), { name: "hello", description: "world" }) // .add(z.number(), { name: "number", description: "number" }); // expect(namedReg.get("hello")).toEqual({ // name: "hello", // description: "world", // }); // expect(namedReg.has("hello")).toEqual(true); // expect(namedReg.get("number")).toEqual({ // name: "number", // description: "number", // }); // // @ts-expect-error // namedReg.get("world"); // // @ts-expect-error // expect(namedReg.get("world")).toEqual(undefined); // const hello = namedReg.get("hello"); // expect(hello).toEqual({ name: "hello", description: "world" }); // expectTypeOf().toEqualTypeOf<{ // name: "hello"; // description: "world"; // }>(); // expectTypeOf().toEqualTypeOf<{ // hello: { name: "hello"; description: "world" }; // number: { name: "number"; description: "number" }; // }>(); // }); test("output type in registry meta", () => { const reg = z.registry<{ out: z.$output }>(); const a = z.string(); reg.add(a, { out: "asdf" }); // @ts-expect-error reg.add(a, 1234); expectTypeOf(reg.get(a)).toEqualTypeOf<{ out: string } | undefined>(); }); test("output type in registry meta - objects and arrays", () => { const reg = z.registry<{ name: string; examples: z.$output[] }>(); const a = z.string(); reg.add(a, { name: "hello", examples: ["world"] }); // @ts-expect-error reg.add(a, { name: "hello", examples: "world" }); expectTypeOf(reg.get(a)).toEqualTypeOf<{ name: string; examples: string[] } | undefined>(); }); test("input type in registry meta", () => { const reg = z.registry<{ in: z.$input }>(); const a = z.pipe(z.number(), z.transform(String)); reg.add(a, { in: 1234 }); // @ts-expect-error reg.add(a, "1234"); expectTypeOf(reg.get(a)).toEqualTypeOf<{ in: number } | undefined>(); }); test("input type in registry meta - objects and arrays", () => { const reg = z.registry<{ name: string; examples: z.$input[] }>(); const a = z.pipe(z.number(), z.transform(String)); reg.add(a, { name: "hello", examples: [1234] }); // @ts-expect-error reg.add(a, { name: "hello", examples: "world" }); expectTypeOf(reg.get(a)).toEqualTypeOf<{ name: string; examples: number[] } | undefined>(); }); test(".meta method", () => { const a1 = z.string(); const a2 = a1.meta({ name: "hello" }); expect(a1.meta()).toEqual(undefined); expect(a2.meta()).toEqual({ name: "hello" }); expect(a1 === a2).toEqual(false); }); test(".meta metadata does not bubble up", () => { const a1 = z.string().meta({ name: "hello" }); const a2 = a1.optional(); expect(a1.meta()).toEqual({ name: "hello" }); expect(a2.meta()).toEqual(undefined); }); test(".describe", () => { const a1 = z.string(); const a2 = a1.describe("Hello"); expect(a1.description).toEqual(undefined); expect(a2.description).toEqual("Hello"); }); test("inherit across clone", () => { const A = z.string().meta({ a: true }); expect(A.meta()).toEqual({ a: true }); const B = A.meta({ b: true }); expect(B.meta()).toEqual({ a: true, b: true }); const C = B.describe("hello"); expect(C.meta()).toEqual({ a: true, b: true, description: "hello" }); }); test("loose examples", () => { z.string().register(z.globalRegistry, { examples: ["example"], }); }); test("function meta witout replacement", () => { const myReg = z.registry<{ defaulter: (arg: string, test: boolean) => number; }>(); const mySchema = z.date(); myReg.add(mySchema, { defaulter: (arg, _test) => { return arg.length; }, }); expect(myReg.get(mySchema)!.defaulter("hello", true)).toEqual(5); }); test("function meta with replacement", () => { const myReg = z.registry<{ defaulter: (arg: z.$input, test: boolean) => z.$output; }>(); const mySchema = z.string().transform((val) => val.length); myReg.add(mySchema, { defaulter: (arg, _test) => { return arg.length; }, }); expect(myReg.get(mySchema)!.defaulter("hello", true)).toEqual(5); }); test("test .clear()", () => { const reg = z.registry(); const a = z.string(); reg.add(a); expect(reg.has(a)).toEqual(true); reg.clear(); expect(reg.has(a)).toEqual(false); });