/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/record.test.ts (8118B)
import { expect, expectTypeOf, test } from "vitest"; import * as z from "zod/v4"; test("type inference", () => { const booleanRecord = z.record(z.string(), z.boolean()); type booleanRecord = typeof booleanRecord._output; const recordWithEnumKeys = z.record(z.enum(["Tuna", "Salmon"]), z.string()); type recordWithEnumKeys = z.infer; const recordWithLiteralKey = z.record(z.literal(["Tuna", "Salmon"]), z.string()); type recordWithLiteralKey = z.infer; const recordWithLiteralUnionKeys = z.record(z.union([z.literal("Tuna"), z.literal("Salmon")]), z.string()); type recordWithLiteralUnionKeys = z.infer; expectTypeOf().toEqualTypeOf>(); expectTypeOf().toEqualTypeOf>(); expectTypeOf().toEqualTypeOf>(); expectTypeOf().toEqualTypeOf>(); }); test("enum exhaustiveness", () => { const schema = z.record(z.enum(["Tuna", "Salmon"]), z.string()); expect( schema.parse({ Tuna: "asdf", Salmon: "asdf", }) ).toEqual({ Tuna: "asdf", Salmon: "asdf", }); expect(schema.safeParse({ Tuna: "asdf", Salmon: "asdf", Trout: "asdf" })).toMatchInlineSnapshot(` { "error": [ZodError: [ { "code": "unrecognized_keys", "keys": [ "Trout" ], "path": [], "message": "Unrecognized key: \\"Trout\\"" } ]], "success": false, } `); expect(schema.safeParse({ Tuna: "asdf" })).toMatchInlineSnapshot(` { "error": [ZodError: [ { "expected": "string", "code": "invalid_type", "path": [ "Salmon" ], "message": "Invalid input: expected string, received undefined" } ]], "success": false, } `); }); test("literal exhaustiveness", () => { const schema = z.record(z.literal(["Tuna", "Salmon"]), z.string()); schema.parse({ Tuna: "asdf", Salmon: "asdf", }); expect(schema.safeParse({ Tuna: "asdf", Salmon: "asdf", Trout: "asdf" })).toMatchInlineSnapshot(` { "error": [ZodError: [ { "code": "unrecognized_keys", "keys": [ "Trout" ], "path": [], "message": "Unrecognized key: \\"Trout\\"" } ]], "success": false, } `); expect(schema.safeParse({ Tuna: "asdf" })).toMatchInlineSnapshot(` { "error": [ZodError: [ { "expected": "string", "code": "invalid_type", "path": [ "Salmon" ], "message": "Invalid input: expected string, received undefined" } ]], "success": false, } `); }); test("pipe exhaustiveness", () => { const schema = z.record(z.enum(["Tuna", "Salmon"]).pipe(z.any()), z.string()); expect(schema.parse({ Tuna: "asdf", Salmon: "asdf" })).toEqual({ Tuna: "asdf", Salmon: "asdf", }); expect(schema.safeParse({ Tuna: "asdf", Salmon: "asdf", Trout: "asdf" })).toMatchInlineSnapshot(` { "error": [ZodError: [ { "code": "unrecognized_keys", "keys": [ "Trout" ], "path": [], "message": "Unrecognized key: \\"Trout\\"" } ]], "success": false, } `); expect(schema.safeParse({ Tuna: "asdf" })).toMatchInlineSnapshot(` { "error": [ZodError: [ { "expected": "string", "code": "invalid_type", "path": [ "Salmon" ], "message": "Invalid input: expected string, received undefined" } ]], "success": false, } `); }); test("union exhaustiveness", () => { const schema = z.record(z.union([z.literal("Tuna"), z.literal("Salmon")]), z.string()); expect(schema.parse({ Tuna: "asdf", Salmon: "asdf" })).toEqual({ Tuna: "asdf", Salmon: "asdf", }); expect(schema.safeParse({ Tuna: "asdf", Salmon: "asdf", Trout: "asdf" })).toMatchInlineSnapshot(` { "error": [ZodError: [ { "code": "unrecognized_keys", "keys": [ "Trout" ], "path": [], "message": "Unrecognized key: \\"Trout\\"" } ]], "success": false, } `); expect(schema.safeParse({ Tuna: "asdf" })).toMatchInlineSnapshot(` { "error": [ZodError: [ { "expected": "string", "code": "invalid_type", "path": [ "Salmon" ], "message": "Invalid input: expected string, received undefined" } ]], "success": false, } `); }); test("string record parse - pass", () => { const schema = z.record(z.string(), z.boolean()); schema.parse({ k1: true, k2: false, 1234: false, }); expect(schema.safeParse({ asdf: 1234 }).success).toEqual(false); expect(schema.safeParse("asdf")).toMatchInlineSnapshot(` { "error": [ZodError: [ { "expected": "record", "code": "invalid_type", "path": [], "message": "Invalid input: expected record, received string" } ]], "success": false, } `); }); test("key and value getters", () => { const rec = z.record(z.string(), z.number()); rec.keyType.parse("asdf"); rec.valueType.parse(1234); }); test("is not vulnerable to prototype pollution", async () => { const rec = z.record( z.string(), z.object({ a: z.string(), }) ); const data = JSON.parse(` { "__proto__": { "a": "evil" }, "b": { "a": "good" } } `); const obj1 = rec.parse(data); expect(obj1.a).toBeUndefined(); const obj2 = rec.safeParse(data); expect(obj2.success).toBe(true); if (obj2.success) { expect(obj2.data.a).toBeUndefined(); } const obj3 = await rec.parseAsync(data); expect(obj3.a).toBeUndefined(); const obj4 = await rec.safeParseAsync(data); expect(obj4.success).toBe(true); if (obj4.success) { expect(obj4.data.a).toBeUndefined(); } }); test("dont remove undefined values", () => { const result1 = z.record(z.string(), z.any()).parse({ foo: undefined }); expect(result1).toEqual({ foo: undefined, }); }); test("allow undefined values", () => { const schema = z.record(z.string(), z.undefined()); expect( Object.keys( schema.parse({ _test: undefined, }) ) ).toEqual(["_test"]); }); test("async parsing", async () => { const schema = z .record( z.string(), z .string() .optional() .refine(async () => true) ) .refine(async () => true); const data = { foo: "bar", baz: "qux", }; const result = await schema.safeParseAsync(data); expect(result.data).toEqual(data); }); test("async parsing", async () => { const schema = z .record( z.string(), z .string() .optional() .refine(async () => false) ) .refine(async () => false); const data = { foo: "bar", baz: "qux", }; const result = await schema.safeParseAsync(data); expect(result.success).toEqual(false); expect(result.error).toMatchInlineSnapshot(` [ZodError: [ { "code": "custom", "path": [ "foo" ], "message": "Invalid input" }, { "code": "custom", "path": [ "baz" ], "message": "Invalid input" }, { "code": "custom", "path": [], "message": "Invalid input" } ]] `); }); test("partial record", () => { const schema = z.partialRecord(z.string(), z.string()); type schema = z.infer; expectTypeOf().toEqualTypeOf>>(); const Keys = z.enum(["id", "name", "email"]).or(z.never()); const Person = z.partialRecord(Keys, z.string()); expectTypeOf>().toEqualTypeOf>>(); });