/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/readonly.test.ts (11777B)
import { expect, expectTypeOf, test } from "vitest"; import * as z from "zod/v4"; enum testEnum { A = 0, B = 1, } test("flat inference", () => { const readonlyString = z.string().readonly(); const readonlyNumber = z.number().readonly(); const readonlyNaN = z.nan().readonly(); const readonlyBigInt = z.bigint().readonly(); const readonlyBoolean = z.boolean().readonly(); const readonlyDate = z.date().readonly(); const readonlyUndefined = z.undefined().readonly(); const readonlyNull = z.null().readonly(); const readonlyAny = z.any().readonly(); const readonlyUnknown = z.unknown().readonly(); const readonlyVoid = z.void().readonly(); const readonlyStringArray = z.array(z.string()).readonly(); const readonlyTuple = z.tuple([z.string(), z.number()]).readonly(); const readonlyMap = z.map(z.string(), z.date()).readonly(); const readonlySet = z.set(z.string()).readonly(); const readonlyStringRecord = z.record(z.string(), z.string()).readonly(); const readonlyNumberRecord = z.record(z.string(), z.number()).readonly(); const readonlyObject = z.object({ a: z.string(), 1: z.number() }).readonly(); const readonlyEnum = z.nativeEnum(testEnum).readonly(); const readonlyPromise = z.promise(z.string()).readonly(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf>(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf>(); expectTypeOf().toEqualTypeOf>(); expectTypeOf().toEqualTypeOf>>(); expectTypeOf().toEqualTypeOf>>(); expectTypeOf().toEqualTypeOf<{ readonly a: string; readonly 1: number }>(); expectTypeOf().toEqualTypeOf>(); expectTypeOf().toEqualTypeOf(); }); // test("deep inference", () => { // expectTypeOf>().toEqualTypeOf(); // expectTypeOf>().toEqualTypeOf(); // expectTypeOf>().toEqualTypeOf(); // expectTypeOf>().toEqualTypeOf(); // expectTypeOf>().toEqualTypeOf(); // expectTypeOf>().toEqualTypeOf(); // expectTypeOf>().toEqualTypeOf(); // expectTypeOf>().toEqualTypeOf(); // expectTypeOf>().toEqualTypeOf(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[9]> // >().toEqualTypeOf>(); // expectTypeOf>().toEqualTypeOf(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[11]> // >().toEqualTypeOf<(args_0: string, args_1: number, ...args_2: unknown[]) => unknown>(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[12]> // >().toEqualTypeOf(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[13]> // >().toEqualTypeOf(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[14]> // >().toEqualTypeOf>(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[15]> // >().toEqualTypeOf>>(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[16]> // >().toEqualTypeOf>>(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[17]> // >().toEqualTypeOf>>(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[18]> // >().toEqualTypeOf<{ readonly a: string; readonly 1: number }>(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[19]> // >().toEqualTypeOf>(); // expectTypeOf< // z.infer<(typeof deepReadonlySchemas_0)[20]> // >().toEqualTypeOf>(); // expectTypeOf< // z.infer // >().toEqualTypeOf, // { // readonly a: { // readonly [x: string]: readonly any[]; // }; // readonly b: { // readonly c: { // readonly d: { // readonly e: { // readonly f: { // readonly g?: {}; // }; // }; // }; // }; // }; // } // >>(); // }); test("object freezing", async () => { expect(Object.isFrozen(z.array(z.string()).readonly().parse(["a"]))).toBe(true); expect(Object.isFrozen(z.tuple([z.string(), z.number()]).readonly().parse(["a", 1]))).toBe(true); expect( Object.isFrozen( z .map(z.string(), z.date()) .readonly() .parse(new Map([["a", new Date()]])) ) ).toBe(true); expect(Object.isFrozen(z.record(z.string(), z.string()).readonly().parse({ a: "b" }))).toBe(true); expect(Object.isFrozen(z.record(z.string(), z.number()).readonly().parse({ a: 1 }))).toBe(true); expect(Object.isFrozen(z.object({ a: z.string(), 1: z.number() }).readonly().parse({ a: "b", 1: 2 }))).toBe(true); expect( Object.isFrozen( await z .set(z.promise(z.string())) .readonly() .parseAsync(new Set([Promise.resolve("a")])) ) ).toBe(true); expect(Object.isFrozen(await z.promise(z.string()).readonly().parseAsync(Promise.resolve("a")))).toBe(true); }); test("async object freezing", async () => { expect(Object.isFrozen(await z.array(z.string()).readonly().parseAsync(["a"]))).toBe(true); expect(Object.isFrozen(await z.tuple([z.string(), z.number()]).readonly().parseAsync(["a", 1]))).toBe(true); expect( Object.isFrozen( await z .map(z.string(), z.date()) .readonly() .parseAsync(new Map([["a", new Date()]])) ) ).toBe(true); expect( Object.isFrozen( await z .set(z.promise(z.string())) .readonly() .parseAsync(new Set([Promise.resolve("a")])) ) ).toBe(true); expect(Object.isFrozen(await z.record(z.string(), z.string()).readonly().parseAsync({ a: "b" }))).toBe(true); expect(Object.isFrozen(await z.record(z.string(), z.number()).readonly().parseAsync({ a: 1 }))).toBe(true); expect( Object.isFrozen(await z.object({ a: z.string(), 1: z.number() }).readonly().parseAsync({ a: "b", 1: 2 })) ).toBe(true); expect(Object.isFrozen(await z.promise(z.string()).readonly().parseAsync(Promise.resolve("a")))).toBe(true); }); test("readonly inference", () => { const readonlyStringArray = z.string().array().readonly(); const readonlyStringTuple = z.tuple([z.string()]).readonly(); const deepReadonly = z.object({ a: z.string() }).readonly(); type readonlyStringArray = z.infer; type readonlyStringTuple = z.infer; type deepReadonly = z.infer; expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf(); expectTypeOf().toEqualTypeOf<{ readonly a: string }>(); }); test("readonly parse", () => { const schema = z.array(z.string()).readonly(); const readonlyArray = ["a", "b", "c"] as const; const mutableArray = ["a", "b", "c"]; const result1 = schema.parse(readonlyArray); const result2 = schema.parse(mutableArray); expect(result1).toEqual(readonlyArray); expect(result2).toEqual(mutableArray); }); test("readonly parse with tuples", () => { const schema = z.tuple([z.string(), z.number()]).readonly(); schema.parse(["a", 1]); }); test("readonly and the get method", () => { const readonlyString = z.string().readonly(); const readonlyNumber1 = z.number().readonly(); const readonlyNumber2 = z.number().readonly(); const readonlyBigInt = z.bigint().readonly(); const readonlyBoolean = z.boolean().readonly(); const readonlyDate = z.date().readonly(); const readonlyUndefined = z.undefined().readonly(); const readonlyNull = z.null().readonly(); const readonlyAny = z.any().readonly(); const readonlyUnknown = z.unknown().readonly(); const readonlyVoid = z.void().readonly(); // const readonlyFunction = z.function(z.tuple([z.string(), z.number()]), z.unknown()).readonly(); const readonlyStringArray = z.string().array().readonly(); const readonlyTuple = z.tuple([z.string(), z.number()]).readonly(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf>(); expectTypeOf>().toEqualTypeOf(); // expectTypeOf>().toEqualTypeOf< // (args_0: string, args_1: number, ...args_2: unknown[]) => unknown // >(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expect(readonlyString.parse("asdf")).toEqual("asdf"); expect(readonlyNumber1.parse(1234)).toEqual(1234); expect(readonlyNumber2.parse(1234)).toEqual(1234); const bigIntVal = BigInt(1); expect(readonlyBigInt.parse(bigIntVal)).toEqual(bigIntVal); expect(readonlyBoolean.parse(true)).toEqual(true); const dateVal = new Date(); expect(readonlyDate.parse(dateVal)).toEqual(dateVal); expect(readonlyUndefined.parse(undefined)).toEqual(undefined); expect(readonlyNull.parse(null)).toEqual(null); expect(readonlyAny.parse("whatever")).toEqual("whatever"); expect(readonlyUnknown.parse("whatever")).toEqual("whatever"); expect(readonlyVoid.parse(undefined)).toEqual(undefined); // expect(readonlyFunction.parse(() => void 0)).toEqual(() => void 0); expect(readonlyStringArray.parse(["asdf"])).toEqual(["asdf"]); expect(readonlyTuple.parse(["asdf", 1234])).toEqual(["asdf", 1234]); });