vitest-dev / vitest-dev/vitest

Show additional error properties in `toThrow` diff view

Open
#8,697 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p3-minor-bug
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided TypeScript reproduction using Vitest 3.2.4 and inspect the failing toThrow diff output in the extension. Trace how error instances and their properties are rendered, then verify that a differing property such as code: 123 appears in the diff while matching the existing error message.】【。

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.