-
Notifications
You must be signed in to change notification settings - Fork 93
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
test.equal fails on objects if one has a null prototype #85
Comments
I did some more digging and found that the library |
Good catch, I wanted to try some other deep equal libraries anyway. this one seems a good candidate |
@lorenzofox3 looks fast! Hope it works with this test case |
I had a chance to have a look your issue this week end. I start to doubt that the assertion library should make the assumption that So I am not keen in modifying the // run this code before the test suite
AssertPrototype.propsEq = function (actual, expected, ...rest) {
return this.equal(Object.assign(Object.create({}),actual), expected, ...rest);
};
// and use t.propsEq instead of t.eq
// or if you prefer to overwrite the default behaviour
const equal = AssertPrototype.equal;
AssertPrototype.equal = function(actual, expected, ...rest){
return equal.call(this, Object.assign(Object.create({}),actual), expected, ...rest)
} Then after we have your feedback on the experience, we can think about the next move Please have a look at that pen |
@lorenzofox3 sorry for the late reply here, my focus has been elsewhere for a while. I totally agree that I think for now we will override
Thanks for the tip and for Edit: I just realised after looking at our code that the issue goes deeper than this. Using |
test.equal
fails in unexpected ways when dealing with objects with a null prototype.I have summed this issue up in two simple test cases:
I suspect this is an issue with the "deep equals" part of zora. From memory of glancing through the code
zora
is using an external library for this, so maybe the correct place for this bug report would be there, but maybe using a different library would also be an option.To be clear: in our real use-case, the objects with null prototype are coming from external libraries (in our case, from
graphql
). I don't fully understand it but there has been a trend in recent years to useObject.create(null)
wherever possible rather than{}
for security reasons, so I don't think this case would be too uncommon.The text was updated successfully, but these errors were encountered: