/opt/canhelp/node_modules/better-auth/node_modules/zod/src/v4/classic/tests
NameSizeModeActions
anyunknown.test.ts6390644editdlrm
apply.test.ts15090644editdlrm
array.test.ts72480644editdlrm
assignability.test.ts67900644editdlrm
async-parsing.test.ts123110644editdlrm
async-refinements.test.ts18670644editdlrm
base.test.ts1790644editdlrm
bigint.test.ts19560644editdlrm
brand.test.ts35740644editdlrm
catch.test.ts78310644editdlrm
coalesce.test.ts7430644editdlrm
codec-examples.test.ts190300644editdlrm
codec.test.ts188530644editdlrm
coerce.test.ts77360644editdlrm
continuability.test.ts80200644editdlrm
custom.test.ts12150644editdlrm
date.test.ts16710644editdlrm
datetime.test.ts119320644editdlrm
default.test.ts92260644editdlrm
describe-meta-checks.test.ts9650644editdlrm
description.test.ts12940644editdlrm
discriminated-unions.test.ts176650644editdlrm
enum.test.ts84880644editdlrm
error-utils.test.ts137440644editdlrm
error.test.ts195020644editdlrm
file.test.ts26410644editdlrm
firstparty.test.ts30450644editdlrm
fix-json-issue.test.ts7710644editdlrm
from-json-schema.test.ts214980644editdlrm
function.test.ts83440644editdlrm
generics.test.ts21620644editdlrm
hash.test.ts32040644editdlrm
index.test.ts311910644editdlrm
instanceof.test.ts16580644editdlrm
intersection.test.ts55550644editdlrm
json.test.ts33270644editdlrm
lazy.test.ts47560644editdlrm
literal.test.ts30950644editdlrm
map.test.ts76220644editdlrm
nan.test.ts6450644editdlrm
nested-refine.test.ts36230644editdlrm
nonoptional.test.ts28410644editdlrm
nullable.test.ts5910644editdlrm
number.test.ts86440644editdlrm
object.test.ts184810644editdlrm
optional.test.ts73320644editdlrm
partial.test.ts129730644editdlrm
pickomit.test.ts68850644editdlrm
pipe.test.ts23380644editdlrm
prefault.test.ts20630644editdlrm
preprocess.test.ts65220644editdlrm
primitive.test.ts76490644editdlrm
promise.test.ts23240644editdlrm
prototypes.test.ts4980644editdlrm
readonly.test.ts117860644editdlrm
record.test.ts172260644editdlrm
recursive-types.test.ts126930644editdlrm
refine.test.ts156490644editdlrm
registries.test.ts73910644editdlrm
set.test.ts56220644editdlrm
standard-schema.test.ts37700644editdlrm
string-formats.test.ts37000644editdlrm
string.test.ts780690644editdlrm
stringbool.test.ts35360644editdlrm
template-literal.test.ts358940644editdlrm
to-json-schema-methods.test.ts101000644editdlrm
to-json-schema.test.ts786390644editdlrm
transform.test.ts82980644editdlrm
tuple.test.ts55320644editdlrm
union.test.ts59360644editdlrm
url.test.ts4020644editdlrm
validations.test.ts67360644editdlrm
void.test.ts3060644editdlrm
Edit: /opt/canhelp/node_modules/better-auth/node_modules/zod/src/v4/classic/tests/intersection.test.ts (5555B)
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 + strip", () => { const A = z.strictObject({ a: z.string() }); const B = z.object({ b: z.string() }); const C = z.intersection(A, B); type C = z.infer; expectTypeOf().toEqualTypeOf<{ a: string } & { b: string }>(); // Keys recognized by either side should work expect(C.parse({ a: "foo", b: "bar" })).toEqual({ a: "foo", b: "bar" }); // Extra keys are stripped (follows strip behavior from B) expect(C.parse({ a: "foo", b: "bar", c: "extra" })).toEqual({ a: "foo", b: "bar" }); }); test("object intersection: strict + strict", () => { const A = z.strictObject({ a: z.string() }); const B = z.strictObject({ b: z.string() }); const C = z.intersection(A, B); // Keys recognized by either side should work expect(C.parse({ a: "foo", b: "bar" })).toEqual({ a: "foo", b: "bar" }); // Keys unrecognized by BOTH sides should error const result = C.safeParse({ a: "foo", b: "bar", c: "extra" }); expect(result.error?.issues).toMatchInlineSnapshot(` [ { "code": "unrecognized_keys", "keys": [ "c", ], "message": "Unrecognized key: "c"", "path": [], }, ] `); }); 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"]]` ); });