-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toThrowError
fails to compare subclass of Error (ZodError).
#7315
Comments
I created a stackblitz repro to start with https://stackblitz.com/edit/vitest-dev-vitest-v3sys5ph?file=test%2Frepro.test.ts It would be great if you can check with Zod side to see what's potential issue. |
The issue is because of it('vitest', () => {
console.log({ ...e1 });
// {
// issues: [
// {
// received: 'aa',
// code: 'invalid_enum_value',
// options: [Array],
// path: [Array],
// message: "Invalid enum value. Expected 'development' | 'production' | 'test', received 'aa'"
// }
// ],
// addIssue: [Function (anonymous)],
// addIssues: [Function (anonymous)],
// name: 'ZodError'
// }
expect(e1.addIssue).toEqual(e2.addIssue);
}); I'm not sure if we need to change something on our side since generalizing One workaround is to use custom equality tester to customize A fix possible on Zod side is to make these two properties |
Thank you very much for your debug and response @hi-ogawa !! It was extremely helpful! 🙏 I've opened an issue on the Zod side: colinhacks/zod#3950 |
Describe the bug
Description
toThrow
andtoThrowError
are failing to compare a thrownZodError
.The test case above successfuly passes using the vitest version
2.1.8
. However it fails with version3.0.2
v2.1.8
v3.0.2
Additional Context
ZodError
is a class that extendsError
:https://github.com/colinhacks/zod/blob/main/src/ZodError.ts#L200
Although, the tests don't pass for Zod, they work fine for a simple
CustomError
:I believe it was introduced in this PR: #5876
i'm opening this issue because I use Zod extensively and love Vitest, but this behavior is preventing me from upgrading to the latest version
If this is not a bug, I apologize and would humbly ask for some guidance on how to make this work.
If this aligns with the library's goals, I'd be thrilled to contribute a PR! ✨
Thank you for your attention and for your amazing open-source work! 🙏
Reproduction
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: