diff --git a/src/__tests__/unions.test.ts b/src/__tests__/unions.test.ts index 8713293ff..6b88bef67 100644 --- a/src/__tests__/unions.test.ts +++ b/src/__tests__/unions.test.ts @@ -32,7 +32,7 @@ test("return valid over invalid", () => { }); }); -test("return dirty result over aborted", () => { +test("union with dirty result", () => { const result = z .union([z.number(), z.string().refine(() => false)]) .safeParse("a"); @@ -40,9 +40,21 @@ test("return dirty result over aborted", () => { if (!result.success) { expect(result.error.issues).toEqual([ { - code: "custom", - message: "Invalid input", - path: [], + code: "invalid_union", + unionErrors: [ + { + code: "invalid_type", + expected: "number", + received: "string", + path: [], + message: "Expected number, received string", + }, + { + code: "custom", + message: "Invalid input", + path: [], + }, + ], }, ]); } @@ -62,23 +74,3 @@ test("readonly union", async () => { union.parse("asdf"); union.parse(12); }); - -test("union of strict objects", async () => { - // ensure bug in 3.23.8 is fixed, where "dirty" parse failures would mean reporting the first error, rather than a proper `invalid_union` with `unionErrors`. - // Demo of bug: https://stackblitz.com/edit/stackblitz-starters-swdj3e?file=index.test.js&startScript=test - const union = z.union([ - z.object({ x: z.number() }).strict(), // - z.object({ y: z.number() }).strict(), - ]); - expect(union.safeParse({ x: 1, y: 1 })).toMatchObject({ - success: false, - error: { - issues: [ - { - code: "invalid_union", - unionErrors: [expect.any(z.ZodError), expect.any(z.ZodError)], - }, - ], - }, - }); -});