Skip to content

Show additional error properties in toThrow diff view #8697

Description

@scripthunter7

Describe the bug

Problem

In Vitest 3, the toThrow / toThrowError matcher now compares both the error instance and its properties. However, if the error instance and the error message are the same, but some random property differs, the extension reports a failure without showing the diff. Instead, I have to manually log the error object to understand what’s different.

Suggested Improvement

It would be very helpful if the diff view could also display the additional properties of the error instance, so the mismatch is immediately visible in the test output

Benefit

Including the additional properties in the diff would make debugging faster and reduce the need for manual logging.

🙏 Thanks for considering this improvement and making this great extension!

Reproduction

expect(() => {
  throw Object.assign(new Error("Something went wrong"), { code: 123 });
}).toThrow(new Error("Something went wrong")); 
// fails, but the diff does not show the extra `code` property

became

Image

Output

No visible diff in the UI (see the screenshot above)

Extension Version

1.28.2

Vitest Version

3.2.4

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    Status
    Approved

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions