vitest-dev / vitest-dev/vitest
Show additional error properties in `toThrow` diff view
Nobody has claimed this yet.
- 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
Output
No visible diff in the UI (see the screenshot above)
Extension Version
1.28.2
Vitest Version
3.2.4
Validations
- Check that you are using the latest version of the extension
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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