zod 4.1.0-canary.20250821T014902 → 4.1.0-canary.20250821T014930
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
CHANGED
|
@@ -152,13 +152,13 @@ test("catchall overrides strict", () => {
|
|
|
152
152
|
});
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
-
test("test that optional keys are unset",
|
|
155
|
+
test("test that optional keys are unset", () => {
|
|
156
156
|
const SNamedEntity = z.object({
|
|
157
157
|
id: z.string(),
|
|
158
158
|
set: z.string().optional(),
|
|
159
159
|
unset: z.string().optional(),
|
|
160
160
|
});
|
|
161
|
-
const result =
|
|
161
|
+
const result = SNamedEntity.parse({
|
|
162
162
|
id: "asdf",
|
|
163
163
|
set: undefined,
|
|
164
164
|
});
|
|
@@ -6,9 +6,9 @@ test("type inference", () => {
|
|
|
6
6
|
expectTypeOf<z.infer<typeof schema>>().toEqualTypeOf<string[]>();
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
test("array min/max",
|
|
9
|
+
test("array min/max", () => {
|
|
10
10
|
const schema = z.array(z.string()).min(2).max(2);
|
|
11
|
-
const r1 =
|
|
11
|
+
const r1 = schema.safeParse(["asdf"]);
|
|
12
12
|
expect(r1.success).toEqual(false);
|
|
13
13
|
expect(r1.error!.issues).toMatchInlineSnapshot(`
|
|
14
14
|
[
|
|
@@ -23,7 +23,7 @@ test("array min/max", async () => {
|
|
|
23
23
|
]
|
|
24
24
|
`);
|
|
25
25
|
|
|
26
|
-
const r2 =
|
|
26
|
+
const r2 = schema.safeParse(["asdf", "asdf", "asdf"]);
|
|
27
27
|
expect(r2.success).toEqual(false);
|
|
28
28
|
expect(r2.error!.issues).toMatchInlineSnapshot(`
|
|
29
29
|
[
|
|
@@ -39,11 +39,11 @@ test("array min/max", async () => {
|
|
|
39
39
|
`);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
test("array length",
|
|
42
|
+
test("array length", () => {
|
|
43
43
|
const schema = z.array(z.string()).length(2);
|
|
44
44
|
schema.parse(["asdf", "asdf"]);
|
|
45
45
|
|
|
46
|
-
const r1 =
|
|
46
|
+
const r1 = schema.safeParse(["asdf"]);
|
|
47
47
|
expect(r1.success).toEqual(false);
|
|
48
48
|
expect(r1.error!.issues).toMatchInlineSnapshot(`
|
|
49
49
|
[
|
|
@@ -59,7 +59,7 @@ test("array length", async () => {
|
|
|
59
59
|
]
|
|
60
60
|
`);
|
|
61
61
|
|
|
62
|
-
const r2 =
|
|
62
|
+
const r2 = schema.safeParse(["asdf", "asdf", "asdf"]);
|
|
63
63
|
expect(r2.success).toEqual(false);
|
|
64
64
|
expect(r2.error!.issues).toMatchInlineSnapshot(`
|
|
65
65
|
[
|
|
@@ -162,13 +162,13 @@ test("catchall overrides strict", () => {
|
|
|
162
162
|
});
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
-
test("optional keys are unset",
|
|
165
|
+
test("optional keys are unset", () => {
|
|
166
166
|
const SNamedEntity = z.object({
|
|
167
167
|
id: z.string(),
|
|
168
168
|
set: z.string().optional(),
|
|
169
169
|
unset: z.string().optional(),
|
|
170
170
|
});
|
|
171
|
-
const result =
|
|
171
|
+
const result = SNamedEntity.parse({
|
|
172
172
|
id: "asdf",
|
|
173
173
|
set: undefined,
|
|
174
174
|
});
|
|
@@ -167,8 +167,8 @@ describe("early termination options", () => {
|
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
describe("custom error paths", () => {
|
|
170
|
-
test("should use custom path in error message",
|
|
171
|
-
const result =
|
|
170
|
+
test("should use custom path in error message", () => {
|
|
171
|
+
const result = z
|
|
172
172
|
.object({ password: z.string(), confirm: z.string() })
|
|
173
173
|
.refine((data) => data.confirm === data.password, { path: ["confirm"] })
|
|
174
174
|
.safeParse({ password: "asdf", confirm: "qewr" });
|
|
@@ -39,7 +39,7 @@ test("valid parse async", async () => {
|
|
|
39
39
|
expect(result.data!.has("second")).toEqual(true);
|
|
40
40
|
expect(result.data!.has("third")).toEqual(false);
|
|
41
41
|
|
|
42
|
-
const asyncResult =
|
|
42
|
+
const asyncResult = stringSet.safeParse(new Set(["first", "second"]));
|
|
43
43
|
expect(asyncResult.success).toEqual(true);
|
|
44
44
|
expect(asyncResult.data!.has("first")).toEqual(true);
|
|
45
45
|
expect(asyncResult.data!.has("second")).toEqual(true);
|