-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ExpectationResult
of a custom asymmetric matcher is ignored
#7730
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
Comments
It looks like Vitest is performing the ActualAssertionError: expected { state: 'mediocre' } to deeply equal { state: toBeGorgeous<> }
- Expected
+ Received
{
- "state": toBeGorgeous<>,
+ "state": "mediocre",
}
Expected
|
It does not fallback to the equality reporting, it performs equality reporting. You are calling I agree that the message can be improved, but as far as I understand this is not a bug. |
What kind of improvement do you suggest? Current scheme doesn't look too bad since it allows things like: vitest/test/core/test/__snapshots__/jest-expect.test.ts.snap Lines 902 to 905 in 0c2924b
vitest/test/core/test/__snapshots__/jest-expect.test.ts.snap Lines 782 to 789 in 0c2924b
|
@sheremet-va, you're right. My focus here is not in the behavior but in how the expectation result is being printed. @hi-ogawa, I suggest that if the currently applied matcher is a custom matcher, always use its expect(b).toBeGorgeous() Given the asymmetric nature of the matcher, which likely implies it's being nested somewhere in the actual data structure, the output for this particular case may be appended with the place where the matcher errors. But performing diff as it is right now makes little sense as it always compares the actual value with the matcher, and that brings me no value as a developer. |
I'm not sure if that approach makes sense in a general, for example when there is multiple asymmetric matcher involved. https://stackblitz.com/edit/vitest-dev-vitest-gp95rpax?file=test%2Fbasic.test.ts expect({ x: 'mediocre', y: 'gorgeous' }).toEqual({
x: expect.toBeGorgeous(),
y: expect.not.toBeGorgeous()
}); - Expected
+ Received
{
- "x": toBeGorgeous<>,
- "y": not.toBeGorgeous<>,
+ "x": "mediocre",
+ "y": "gorgeous",
} Btw, can you explain an actual use case? I appreciate the minimal repro, but simplified "gorgeous" example can make it less convincing about the change you're suggesting. |
Describe the bug
When I have a custom asymmetric matcher, Vitest applies it correctly but disregards the matcher's
ExpectationResult
properties likemessage
,actual
, andexpected
if the matcher fails. I expect the inverse assertions (.not
) to have the same problem.Reproduction
Here's a sandbox: https://stackblitz.com/edit/vitest-dev-vitest-je43znvc?file=vite.config.ts,vitest.setup.ts,test%2Fbasic.test.ts&initialPath=__vitest__/
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: