-
-
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
fix(expect)!: check more properties for error equality #5876
base: main
Are you sure you want to change the base?
fix(expect)!: check more properties for error equality #5876
Conversation
This reverts commit 33e71aa.
@hi-ogawa is there anything specific that keeps this PR in draft? Can I help? |
I had a concern about whether we should print diff when custom properties are different. Currently, Vitest cannot show any diff in this case since pretty-format strips it off. Fortunately, chai/loupe can print them, but it's possible that the message will be truncated and not visible to users. This is an example from test cases: exports[`Error equality > basic 4`] = `
{
"actual": "[Error: hello]",
"diff": "Compared values have no visual difference.",
"expected": "[Error: hello]",
"message": "expected Error: hello { cause: 'x' } to deeply equal Error: hello { cause: 'y' }",
}
`; Do you think it's worth changing pretty-format side (I haven't attempted anything yet whether it's possible or not) or just keep it as is and rely on chai error message? |
I think we can maybe introduce a flag in |
6fae26a
to
755cfb8
Compare
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
packages/expect/src/jest-utils.ts
Outdated
// - Only enumerable "own" properties are considered. | ||
// - Error names, messages, causes, and errors are always compared, even if these are not enumerable properties. errors is also compared. | ||
// (NOTE: causes and errors are added in v22) | ||
return ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rewrite it as a bunch of if
statements? This is hard to process 😄
Description
toEqual/toStrictEqual
does not check custom Error properties #5244NodeJs PR for a reference
todo
cause
diffit can fail due to chai's error message generationMaximum call stack size exceeded
when assertion fails with cyclic references ofError.cause
chaijs/chai#1645 Fixed!toThrowError(new Error(...))
usage too? (I think so)Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.