-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
Unexpected behavior in current deepEqual
function
#2048
Comments
These are additional behaviors I uncovered but are not fixed by the above possible solution. deepEqual([ 'a', 'b' ], ['b', 'a'])
// false, but possibly not in the spirit of matching
deepEqual([ 'a', 'b' ], { '0': 'a', '1': 'b' })
// true, but doesn't seem intuitively correct |
Thanks for this, I agree this is a bug. The tests cases you provided are great. I'll play around with this over the weekend. I think I'm inclined to separate the array and object comparisons into separate flows. If for no other reason than to improve readability around the magic of getting the keys on an array. |
🎉 This issue has been resolved in version 13.0.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Concerning the
deepEqual
function currently here: https://github.com/nock/nock/blob/main/lib/common.js#L570-L590Behavior
I have run into an issue with expecting fields to be
undefined
in request bodies. The following behavior is observed:These problems stem from the serialization/deserialization of JSON bodies on requests, since
undefined
is not serializable in JSON. So the value ofexpected
is not modified bynock
, while the value ofactual
is more trulyJSON.parse(JSON.stringify(actual))
since the payload is first serialized by the request lib and then deserialized bynock
.There is a very slight performance gain in the current implementation which assumes that two objects with differing number of keys are not equal. Case 2 (from above) sneakily slips past this check, which gives me the result I want, but for the wrong reason, and is incongruous with Case 1. I also don't believe this strictness is the real spirit of the matching functionality of
nock
:As in Case 1, if I expect a body of
{ a: 'a', b: undefined }
, I am asserting thatb
should be undefined/not present in the request body, so I think that{"a":"a"}
should be a valid/matched request body.Possible solution
Modify the
deepEqual
function, like so:This passes every existing test case, plus fixes the problems noted above.
How to reproduce the issue
See above.
Does the bug have a test case?
Not yet.
Versions
The text was updated successfully, but these errors were encountered: