zod 4.2.0-canary.20251124T022609 → 4.2.0-canary.20251202T062120
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/v3/tests/complex.test.ts +17 -3
- package/src/v3/tests/function.test.ts +7 -3
- package/src/v3/tests/nan.test.ts +5 -2
- package/src/v4/core/util.ts +1 -1
- package/src/v4/core/versions.ts +1 -1
- package/v4/core/util.cjs +1 -1
- package/v4/core/util.js +1 -1
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { test } from "vitest";
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
2
|
import * as z from "zod/v3";
|
|
3
3
|
|
|
4
4
|
const crazySchema = z.object({
|
|
@@ -40,7 +40,7 @@ const crazySchema = z.object({
|
|
|
40
40
|
// });
|
|
41
41
|
|
|
42
42
|
test("parse", () => {
|
|
43
|
-
|
|
43
|
+
const input = {
|
|
44
44
|
tuple: ["asdf", 1234, true, null, undefined, "1234"],
|
|
45
45
|
merged: { k1: "asdf", k2: 12 },
|
|
46
46
|
union: ["asdf", 12, "asdf", 12, "asdf", 12],
|
|
@@ -52,5 +52,19 @@ test("parse", () => {
|
|
|
52
52
|
nonstrict: { points: 1234 },
|
|
53
53
|
numProm: Promise.resolve(12),
|
|
54
54
|
lenfun: (x: string) => x.length,
|
|
55
|
-
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const result = crazySchema.parse(input);
|
|
58
|
+
|
|
59
|
+
// Verify the parsed result structure
|
|
60
|
+
expect(result.tuple).toEqual(input.tuple);
|
|
61
|
+
expect(result.merged).toEqual(input.merged);
|
|
62
|
+
expect(result.union).toEqual(input.union);
|
|
63
|
+
expect(result.array).toEqual(input.array);
|
|
64
|
+
expect(result.sumMinLength).toEqual(input.sumMinLength);
|
|
65
|
+
expect(result.intersection).toEqual(input.intersection);
|
|
66
|
+
expect(result.enum).toEqual(input.enum);
|
|
67
|
+
expect(result.nonstrict).toEqual(input.nonstrict);
|
|
68
|
+
expect(result.numProm).toBeInstanceOf(Promise);
|
|
69
|
+
expect(typeof result.lenfun).toBe("function");
|
|
56
70
|
});
|
|
@@ -10,7 +10,8 @@ const func1 = z.function(args1, returns1);
|
|
|
10
10
|
|
|
11
11
|
test("function parsing", () => {
|
|
12
12
|
const parsed = func1.parse((arg: any) => arg.length);
|
|
13
|
-
parsed("asdf");
|
|
13
|
+
const result = parsed("asdf");
|
|
14
|
+
expect(result).toBe(4);
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
test("parsed function fail 1", () => {
|
|
@@ -226,8 +227,11 @@ test("allow extra parameters", () => {
|
|
|
226
227
|
test("params and returnType getters", () => {
|
|
227
228
|
const func = z.function().args(z.string()).returns(z.string());
|
|
228
229
|
|
|
229
|
-
func.parameters().items[0].parse("asdf");
|
|
230
|
-
|
|
230
|
+
const paramResult = func.parameters().items[0].parse("asdf");
|
|
231
|
+
expect(paramResult).toBe("asdf");
|
|
232
|
+
|
|
233
|
+
const returnResult = func.returnType().parse("asdf");
|
|
234
|
+
expect(returnResult).toBe("asdf");
|
|
231
235
|
});
|
|
232
236
|
|
|
233
237
|
test("inference with transforms", () => {
|
package/src/v3/tests/nan.test.ts
CHANGED
|
@@ -6,8 +6,11 @@ import * as z from "zod/v3";
|
|
|
6
6
|
const schema = z.nan();
|
|
7
7
|
|
|
8
8
|
test("passing validations", () => {
|
|
9
|
-
schema.parse(Number.NaN);
|
|
10
|
-
|
|
9
|
+
const result1 = schema.parse(Number.NaN);
|
|
10
|
+
expect(Number.isNaN(result1)).toBe(true);
|
|
11
|
+
|
|
12
|
+
const result2 = schema.parse(Number("Not a number"));
|
|
13
|
+
expect(Number.isNaN(result2)).toBe(true);
|
|
11
14
|
});
|
|
12
15
|
|
|
13
16
|
test("failing validations", () => {
|
package/src/v4/core/util.ts
CHANGED
|
@@ -199,7 +199,7 @@ export function assertNotEqual<A, B>(val: AssertNotEqual<A, B>): AssertNotEqual<
|
|
|
199
199
|
export function assertIs<T>(_arg: T): void {}
|
|
200
200
|
|
|
201
201
|
export function assertNever(_x: never): never {
|
|
202
|
-
throw new Error();
|
|
202
|
+
throw new Error("Unexpected value in exhaustive check");
|
|
203
203
|
}
|
|
204
204
|
export function assert<T>(_: any): asserts _ is T {}
|
|
205
205
|
|
package/src/v4/core/versions.ts
CHANGED
package/v4/core/util.cjs
CHANGED
package/v4/core/util.js
CHANGED
|
@@ -7,7 +7,7 @@ export function assertNotEqual(val) {
|
|
|
7
7
|
}
|
|
8
8
|
export function assertIs(_arg) { }
|
|
9
9
|
export function assertNever(_x) {
|
|
10
|
-
throw new Error();
|
|
10
|
+
throw new Error("Unexpected value in exhaustive check");
|
|
11
11
|
}
|
|
12
12
|
export function assert(_) { }
|
|
13
13
|
export function getEnumValues(entries) {
|
package/v4/core/versions.cjs
CHANGED
package/v4/core/versions.js
CHANGED