/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/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"]]` ); });