vitest-dev / vitest-dev/vitest
More Strict Error Equality fails with mswjs HttpResponse.error()
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
mswjs uses another way to add the cause of an error to the error itself, so the diff, based on keys
eq({...a}, {....b) ...
fails, but should not
currently we will remove the cause from the expected result manually to compare without it.
Reproduction
const NewError = new Error('hi');
const NewErrorWithCause = new Error('hi', { cause: 'x' });
const NewErrorWithAssignedCause = Object.assign(new Error('hi'), {
cause: 'x',
});
// examples from https://vitest.dev/guide/migration.html#more-strict-error-equality
// same as
// expect(new Error('hi', { cause: 'x' })).toEqual(new Error('hi')); // ✅
expect(NewErrorWithCause).toEqual(NewError); // ✅
// same as
// expect(new Error('hi')).toEqual(new Error('hi', { cause: 'x' })); // ❌
expect(NewError).toEqual(NewErrorWithCause); // ❌
// examples based on
// https://github.com/mswjs/interceptors/blob/7410d45a919bacadc2995d6173f3f7e7340f6e50/src/interceptors/fetch/utils/createNetworkError.ts
// https://github.com/mswjs/interceptors/blob/main/src/interceptors/fetch/utils/createNetworkError.ts
expect(NewErrorWithAssignedCause).toEqual(NewError); // should be ✅ -> but is ❌
expect(NewErrorWithAssignedCause).toEqual(NewErrorWithCause); // should be ✅ -> but is ❌
### System Info
```shell
System:
OS: Windows 11 10.0.22631
CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-1260P
Memory: 12.65 GB / 31.71 GB
Binaries:
Node: 22.16.0
npm: 10.9.2
Browsers:
Edge: Chromium (132.0.2957.140)
Internet Explorer: 11.0.22621.3527
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- 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 by reproducing the examples in the issue around more-strict error equality, including errors created with Error.cause and errors whose cause is assigned afterward. Read the linked Vitest migration guidance and the referenced mswjs createNetworkError implementation to compare the error shapes. Done means the assigned-cause cases match the expected equality behavior without manual cause removal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100