/
home
/
techb158
/
balavpn.abdallabala.com
/
node_modules
/
zod
/
src
/
v4
/
classic
/
tests
/
/home/techb158/balavpn.abdallabala.com/node_modules/zod/src/v4/classic/tests
mkdir
upload
Name
Size
Mode
Actions
anyunknown.test.ts
639
0666
edit
dl
rm
array.test.ts
7284
0666
edit
dl
rm
assignability.test.ts
6790
0666
edit
dl
rm
async-parsing.test.ts
12311
0666
edit
dl
rm
async-refinements.test.ts
1867
0666
edit
dl
rm
base.test.ts
179
0666
edit
dl
rm
bigint.test.ts
1956
0666
edit
dl
rm
brand.test.ts
2206
0666
edit
dl
rm
catch.test.ts
7224
0666
edit
dl
rm
coalesce.test.ts
743
0666
edit
dl
rm
coerce.test.ts
7736
0666
edit
dl
rm
continuability.test.ts
7478
0666
edit
dl
rm
custom.test.ts
1215
0666
edit
dl
rm
date.test.ts
962
0666
edit
dl
rm
datetime.test.ts
11511
0666
edit
dl
rm
default.test.ts
7717
0666
edit
dl
rm
description.test.ts
1294
0666
edit
dl
rm
discriminated-unions.test.ts
16810
0666
edit
dl
rm
enum.test.ts
8488
0666
edit
dl
rm
error-utils.test.ts
12572
0666
edit
dl
rm
error.test.ts
19502
0666
edit
dl
rm
file.test.ts
2460
0666
edit
dl
rm
firstparty.test.ts
2977
0666
edit
dl
rm
function.test.ts
6299
0666
edit
dl
rm
generics.test.ts
2162
0666
edit
dl
rm
index.test.ts
27562
0666
edit
dl
rm
instanceof.test.ts
1052
0666
edit
dl
rm
intersection.test.ts
4763
0666
edit
dl
rm
json.test.ts
3309
0666
edit
dl
rm
lazy.test.ts
4756
0666
edit
dl
rm
literal.test.ts
2478
0666
edit
dl
rm
map.test.ts
4817
0666
edit
dl
rm
nan.test.ts
645
0666
edit
dl
rm
nested-refine.test.ts
3623
0666
edit
dl
rm
nonoptional.test.ts
2405
0666
edit
dl
rm
nullable.test.ts
591
0666
edit
dl
rm
number.test.ts
7827
0666
edit
dl
rm
object.test.ts
15999
0666
edit
dl
rm
optional.test.ts
4130
0666
edit
dl
rm
partial.test.ts
4835
0666
edit
dl
rm
pickomit.test.ts
4422
0666
edit
dl
rm
pipe.test.ts
1848
0666
edit
dl
rm
prefault.test.ts
1007
0666
edit
dl
rm
preprocess.test.ts
6959
0666
edit
dl
rm
primitive.test.ts
7649
0666
edit
dl
rm
promise.test.ts
2315
0666
edit
dl
rm
prototypes.test.ts
498
0666
edit
dl
rm
readonly.test.ts
11777
0666
edit
dl
rm
record.test.ts
8118
0666
edit
dl
rm
recursive-types.test.ts
7335
0666
edit
dl
rm
refine.test.ts
14774
0666
edit
dl
rm
registries.test.ts
5999
0666
edit
dl
rm
set.test.ts
5572
0666
edit
dl
rm
standard-schema.test.ts
1369
0666
edit
dl
rm
string-formats.test.ts
3068
0666
edit
dl
rm
string.test.ts
64124
0666
edit
dl
rm
stringbool.test.ts
2333
0666
edit
dl
rm
template-literal.test.ts
34836
0666
edit
dl
rm
to-json-schema.test.ts
59276
0666
edit
dl
rm
transform.test.ts
6000
0666
edit
dl
rm
tuple.test.ts
4702
0666
edit
dl
rm
union.test.ts
2497
0666
edit
dl
rm
validations.test.ts
6736
0666
edit
dl
rm
void.test.ts
306
0666
edit
dl
rm
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<typeof C>; expectTypeOf<C>().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<typeof C>; expectTypeOf<C>().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<typeof C>; expectTypeOf<C>().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<z.infer<typeof Cat>>; expectTypeOf<Cat>().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"]]` ); });
Save
cmd:
run