expect: compare URLs by href (so that different URLs aren't considered equal) #4614
Closed
4 tasks done
Labels
enhancement
New feature or request
good first issue
Good for newcomers
p2-nice-to-have
Not breaking anything but nice to have (priority)
pr welcome
Clear and concise description of the problem
When comparing URLs in Vitest, tests easily pass for completely different URLs (in a sense, this can be considered a bug):
The main equals comparison utility can be easily updated to handle this case better. I'd be happy to contribute this.
Suggested solution
Add a special case for
URL
objects in https://github.com/vitest-dev/vitest/blob/main/packages/expect/src/jest-utils.ts#L96-L97:And add test cases for this in https://github.com/vitest-dev/vitest/blob/main/test/core/test/jest-expect.test.ts#L51-L52:
Alternative
Fail URL comparisons unless they're the exact same object.
Additional context
I initially noticed this behavior while working on a small wrapper around fetch where I have a lot of tests that very roughly look like this (though in place of
fetch
I'm calling my fetch wrapper, replaced here for brevity):I noticed that I couldn't get the assertion to fail at all. As a workaround, my tests actually look like this:
While this works great, it's really a little too cumbersome for my liking. Using
toHaveBeenCalledWith
would be much nicer for this use case.Validations
The text was updated successfully, but these errors were encountered: