-
Notifications
You must be signed in to change notification settings - Fork 666
fix(assert): support Request objects in equal()
#6982
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6982 +/- ##
==========================================
- Coverage 94.26% 94.26% -0.01%
==========================================
Files 602 602
Lines 43662 43678 +16
Branches 7063 7071 +8
==========================================
+ Hits 41159 41174 +15
- Misses 2447 2448 +1
Partials 56 56 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I might be wrong, but I think input validation is the better way of handling this. We could add: This should be added right after the We could consider doing the same for functions like described here. |
This seems reasonable, given that With logic as of current PR: // true
equal(
new Request('null://', { method: 'POST', body: '' }),
new Request('null://', { method: 'POST', body: 'some content' }),
) |
|
Here's an alternative PR that solves it with input validation instead: #6984. |
|
This change feels confusing to me too as bodies are not compared as pointed by Lionel. There is special note about @iuioiua In what situation, did you find the existing behavior inconvenient? Can you share some examples? |
Again, while not true 100% of the time, it's likely that the bodies are the same if other properties are the same. E.g. if the content-length header, the content-type header and the
import { assertSpyCall, stub } from "@std/testing/mock";
using fetchStub = stub(globalThis, "fetch");
await fetch(new Request("https://example.com"));
assertSpyCall(fetchStub, 0, {
args: [new Request("https://example.com")],
});In my specific use case, the package I'm using passes in a |
|
@iuioiua new Request('foo:', { method: 'POST', body: 'bar' }).headers.get('content-length') // nullChecking |
|
Yes, of course the content-length header can be incorrect. As I already said, this is not full proof. But it beats being completely unable to check that 2 of these objects aren't equal in practical terms. |
It's less that it's incorrect, more that it's usually
IMO a function that promises to check for equality should at minimum never return false positives, except maybe in extreme corner cases. False negatives, while best avoided where possible, are more forgivable when those are based on properties that aren't reference equal and that can't be checked for value equality. In some such cases, such as the case of contentful |
|
I propose to close this PR, since we went with the documentation based approach: #6989 |
Previously, this would evaluate to
falsebecause of internal symbols withinRequestobjects being unequal:This would have knock-on effects due to
equal()being the underlying function for comparison withinassertEquals(),assertSpyCall(), etc.This PR is a quick and dirty fix for handling the comparison of said
Requestobjects inequal(). I'm sure there's a better way to do this, but at least this improvesequal()a little.