-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Preserve asymmetric matcher messages #4093
Comments
Though I'm not sure how the output looked like at the time of this issue report, it seems currently the error diff includes the detail of custom asymmetric matcher at least: https://stackblitz.com/edit/github-o6sfsk?file=tests%2Fvitest.test.ts
If there are some other cases you wish to be improved but not in the above example, then I would appreciate if you can provide more details on such cases (preferably with reproduction). The reason why Assuming that pretty-format's vitest/packages/expect/src/jest-extend.ts Lines 108 to 110 in 9ec3f74
[Symbol.for('chai/inspect')]() {
return this.toAsymmetricMatcher()
} The luck of the detail for vitest/packages/expect/src/jest-expect.ts Lines 595 to 605 in 8ed285e
|
Clear and concise description of the problem
I am using asymmetric matchers in my code. Some of these are written by me and I know for sure that they produce good error messages and diffs. When using these asymmetric matchers using
expect(value).myMatcher(...)
then these messages and diffs are printed correctly. However, when using them as asymmetric matchers it gives various uninformative error messages. For example.toEqual(expect.myMatcher())
givesAssertionError: expected <actual value> to deeply equal CustomMatcher{ …(3) }
and.toThrow(expect.myMatcher()
givesAssertionError: expected error to match asymmetric matcher
. In most cases the expected value and the custom messages returned by the matcher are missing and in some cases, for example with.toThrow(..)
the actual value is also missing.Suggested solution
It would be nice if the messages and diffs produced by asymmetric matchers were preserved in some form in the final output.
Alternative
The only alternatives I see are trying to fix tests without knowing what the actual mismatch is and/or not using asymmetric matchers. Neither is ideal.
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: