/opt/canhelp/node_modules/zod/src/v4/classic/tests
NameSizeModeActions
anyunknown.test.ts6390644editdlrm
array.test.ts72840644editdlrm
assignability.test.ts67900644editdlrm
async-parsing.test.ts123110644editdlrm
async-refinements.test.ts18670644editdlrm
base.test.ts1790644editdlrm
bigint.test.ts19560644editdlrm
brand.test.ts22060644editdlrm
catch.test.ts72240644editdlrm
coalesce.test.ts7430644editdlrm
coerce.test.ts77360644editdlrm
continuability.test.ts74780644editdlrm
custom.test.ts12150644editdlrm
date.test.ts9620644editdlrm
datetime.test.ts115110644editdlrm
default.test.ts77170644editdlrm
description.test.ts12940644editdlrm
discriminated-unions.test.ts168100644editdlrm
enum.test.ts84880644editdlrm
error-utils.test.ts125720644editdlrm
error.test.ts195020644editdlrm
file.test.ts24600644editdlrm
firstparty.test.ts29770644editdlrm
function.test.ts62990644editdlrm
generics.test.ts21620644editdlrm
index.test.ts275620644editdlrm
instanceof.test.ts10520644editdlrm
intersection.test.ts47630644editdlrm
json.test.ts33090644editdlrm
lazy.test.ts47560644editdlrm
literal.test.ts24780644editdlrm
map.test.ts48170644editdlrm
nan.test.ts6450644editdlrm
nested-refine.test.ts36230644editdlrm
nonoptional.test.ts24050644editdlrm
nullable.test.ts5910644editdlrm
number.test.ts78270644editdlrm
object.test.ts159990644editdlrm
optional.test.ts41300644editdlrm
partial.test.ts48350644editdlrm
pickomit.test.ts44220644editdlrm
pipe.test.ts18480644editdlrm
prefault.test.ts10070644editdlrm
preprocess.test.ts69590644editdlrm
primitive.test.ts76490644editdlrm
promise.test.ts23150644editdlrm
prototypes.test.ts4980644editdlrm
readonly.test.ts117770644editdlrm
record.test.ts81180644editdlrm
recursive-types.test.ts73350644editdlrm
refine.test.ts147740644editdlrm
registries.test.ts59990644editdlrm
set.test.ts55720644editdlrm
standard-schema.test.ts13690644editdlrm
string-formats.test.ts30680644editdlrm
string.test.ts641240644editdlrm
stringbool.test.ts23330644editdlrm
template-literal.test.ts348360644editdlrm
to-json-schema.test.ts592760644editdlrm
transform.test.ts60000644editdlrm
tuple.test.ts47020644editdlrm
union.test.ts24970644editdlrm
validations.test.ts67360644editdlrm
void.test.ts3060644editdlrm
Edit: /opt/canhelp/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); });