Skip to content

Commit

Permalink
copy test from colinhacks#2719
Browse files Browse the repository at this point in the history
  • Loading branch information
yukukotani committed Feb 7, 2024
1 parent db9974a commit 619b985
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
33 changes: 33 additions & 0 deletions deno/lib/__tests__/transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,39 @@ test("preprocess as the second property of object", () => {
}
});

test("preprocess validates with sibling errors", () => {
expect(() => {
z.object({
// Must be first
missing: z.string().refine(() => false),
preprocess: z.preprocess(
(data: any) => data?.trim(),
z.string().regex(/ asdf/)
),
}).parse({ preprocess: " asdf" });
}).toThrow(
JSON.stringify(
[
{
code: "invalid_type",
expected: "string",
received: "undefined",
path: ["missing"],
message: "Required",
},
{
validation: "regex",
code: "invalid_string",
message: "Invalid",
path: ["preprocess"],
},
],
null,
2
)
);
});

test("async short circuit on dirty", async () => {
const schema = z
.string()
Expand Down
33 changes: 33 additions & 0 deletions src/__tests__/transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,39 @@ test("preprocess as the second property of object", () => {
}
});

test("preprocess validates with sibling errors", () => {
expect(() => {
z.object({
// Must be first
missing: z.string().refine(() => false),
preprocess: z.preprocess(
(data: any) => data?.trim(),
z.string().regex(/ asdf/)
),
}).parse({ preprocess: " asdf" });
}).toThrow(
JSON.stringify(
[
{
code: "invalid_type",
expected: "string",
received: "undefined",
path: ["missing"],
message: "Required",
},
{
validation: "regex",
code: "invalid_string",
message: "Invalid",
path: ["preprocess"],
},
],
null,
2
)
);
});

test("async short circuit on dirty", async () => {
const schema = z
.string()
Expand Down

0 comments on commit 619b985

Please sign in to comment.