/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/intersection.test.ts (4763B)
import { expect, expectTypeOf, test } from "vitest"; import type { util } from "zod/v4/core"; import * as z from "zod/v4"; test("object intersection", () => { const A = z.object({ a: z.string() }); const B = z.object({ b: z.string() }); const C = z.intersection(A, B); // BaseC.merge(HasID); type C = z.infer; expectTypeOf().toEqualTypeOf<{ a: string } & { b: string }>(); const data = { a: "foo", b: "foo" }; expect(C.parse(data)).toEqual(data); expect(() => C.parse({ a: "foo" })).toThrow(); }); test("object intersection: loose", () => { const A = z.looseObject({ a: z.string() }); const B = z.object({ b: z.string() }); const C = z.intersection(A, B); // BaseC.merge(HasID); type C = z.infer; expectTypeOf().toEqualTypeOf<{ a: string; [x: string]: unknown } & { b: string }>(); const data = { a: "foo", b: "foo", c: "extra" }; expect(C.parse(data)).toEqual(data); expect(() => C.parse({ a: "foo" })).toThrow(); }); test("object intersection: strict", () => { const A = z.strictObject({ a: z.string() }); const B = z.object({ b: z.string() }); const C = z.intersection(A, B); // BaseC.merge(HasID); type C = z.infer; expectTypeOf().toEqualTypeOf<{ a: string } & { b: string }>(); const data = { a: "foo", b: "foo", c: "extra" }; const result = C.safeParse(data); expect(result.success).toEqual(false); }); test("deep intersection", () => { const Animal = z.object({ properties: z.object({ is_animal: z.boolean(), }), }); const Cat = z.intersection( z.object({ properties: z.object({ jumped: z.boolean(), }), }), Animal ); type Cat = util.Flatten>; expectTypeOf().toEqualTypeOf<{ properties: { is_animal: boolean } & { jumped: boolean } }>(); const a = Cat.safeParse({ properties: { is_animal: true, jumped: true } }); expect(a.data!.properties).toEqual({ is_animal: true, jumped: true }); }); test("deep intersection of arrays", async () => { const Author = z.object({ posts: z.array( z.object({ post_id: z.number(), }) ), }); const Registry = z.intersection( Author, z.object({ posts: z.array( z.object({ title: z.string(), }) ), }) ); const posts = [ { post_id: 1, title: "Novels" }, { post_id: 2, title: "Fairy tales" }, ]; const cat = Registry.parse({ posts }); expect(cat.posts).toEqual(posts); const asyncCat = await Registry.parseAsync({ posts }); expect(asyncCat.posts).toEqual(posts); }); test("invalid intersection types", async () => { const numberIntersection = z.intersection( z.number(), z.number().transform((x) => x + 1) ); expect(() => { numberIntersection.parse(1234); }).toThrowErrorMatchingInlineSnapshot(`[Error: Unmergable intersection. Error path: []]`); }); test("invalid array merge (incompatible lengths)", async () => { const stringArrInt = z.intersection( z.string().array(), z .string() .array() .transform((val) => [...val, "asdf"]) ); expect(() => stringArrInt.safeParse(["asdf", "qwer"])).toThrowErrorMatchingInlineSnapshot( `[Error: Unmergable intersection. Error path: []]` ); }); test("invalid array merge (incompatible elements)", async () => { const stringArrInt = z.intersection( z.string().array(), z .string() .array() .transform((val) => [...val.slice(0, -1), "asdf"]) ); expect(() => stringArrInt.safeParse(["asdf", "qwer"])).toThrowErrorMatchingInlineSnapshot( `[Error: Unmergable intersection. Error path: [1]]` ); }); test("invalid object merge", async () => { const Cat = z.object({ phrase: z.string().transform((val) => `${val} Meow`), }); const Dog = z.object({ phrase: z.string().transform((val) => `${val} Woof`), }); const CatDog = z.intersection(Cat, Dog); expect(() => CatDog.parse({ phrase: "Hello, my name is CatDog." })).toThrowErrorMatchingInlineSnapshot( `[Error: Unmergable intersection. Error path: ["phrase"]]` ); }); test("invalid deep merge of object and array combination", async () => { const University = z.object({ students: z.array( z.object({ name: z.string().transform((val) => `Student name: ${val}`), }) ), }); const Registry = z.intersection( University, z.object({ students: z.array( z.object({ name: z.string(), surname: z.string(), }) ), }) ); const students = [{ name: "John", surname: "Doe" }]; expect(() => Registry.parse({ students })).toThrowErrorMatchingInlineSnapshot( `[Error: Unmergable intersection. Error path: ["students",0,"name"]]` ); });