-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
assert: check object prototype in deepEqual
#621
Conversation
assert.throws(makeBlock(a.deepEqual, new Boolean(true), {}), a.AssertionError); | ||
|
||
// prototypes | ||
assert.throws(makeBlock(assert.deepEqual, Object.create({}), {}), a.AssertionError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long line, please wrap at 80 columns. If you use vim, adding the following to your .vimrc gives you a visual indicator:
set textwidth=80
set colorcolumn=+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that. I actually DO have a guideline, but in this case I saw some long lines just above and ignored it. Anyway, wrapped this and other offending lines.
LGTM apart from the long lines. I'd like one or two other contributors to sign off on this as well. Can you update the commit log with a few lines explaining what changed and why? |
e0b88b5
to
a77effa
Compare
@bnoordhuis updated. I labeled this PR as |
Don't hate me but textwidth=72 in commit logs. :-) I have a Summoning more @iojs/collaborators. |
Objects with different prototypes should not be considered deep equal, e.g. `assert.deepEqual({}, [])` should throw. Previously `deepEqual` was implemented as per CommonJS Unit Testing/1.0 spec. It states that objects should have 'an identical "prototype" property' to be considered deep equal, which is incorrect. Instead object prototypes should be compared, i.e. `Object.getPrototypeOf` or `__proto__`. Fixes: nodejs#620
I'm +1 on this. |
a77effa
to
5fd9451
Compare
LGTM |
1 similar comment
LGTM |
I'm not so sure, people might expect this to be CommonJS compliant, even though the spec is horribly broken (and |
I'm not convinced either, I can imagine this breaking a whole lot of userland code, let's try and solicit broader feedback, particularly from people implementing other assertion libraries and test runners. |
Some poeple I can think of that may be able to muster an opinion on this change (and may even be impacted by it): @substack, @cjohansen, @isaacs, @thlorenz semver-major is also going to complicate getting this merged because we haven't even figured out how to handle semver-minor branching and releases yet. |
Please don't change the behavior of This makes impossible to compare an object sent over the network in the JSON format and an instance of a model without creating another instance of the model. |
+1 to what @neumino said. Prototype equality means that you can't compare a model object with a plain JS object for quick assertions |
I've mainly been using The question is what does deepEqual mean regarding non-primitive types?
Neither is clear from the docs:
I understand the current check for However, whether the current behavior is due to some misunderstanding or not, changing it now as proposed in this PR is problematic. The CommonJS Unit testing Wiki is not a specification, but merely a collection of suggestions.
Additionally io.js deviated from these in other areas as well. Taking all this into account I'd suggest to stick with the current behavior for |
-1 from me as well since it will break existing apps and isn't necessarily "more correct" behavior than current behavior. Either a new method or an option seems safer. |
Do we actually have a way to test at least how many modules/tests on npm would break with this change? |
LGTM, but this is semver-major like the label states. @thlorenz i'm interested in making some acceptance test build system described in nodejs/roadmap#11, just need to plan it out in iojs/build. |
as a non-breaking alternative: introduce |
The problem is that deep and strict are mutually exclusive conceptually. +1 to |
I'm -1 on this personally the times I use deep equality are on things that aren't the same but are at least shaped the same. I.e. structural equivalence or 'duck typed'. |
To fill the void, you could add a function like referee's assert.match (although with less flexibility/confusing amounts of input types) - |
thanks for the feedback! the PR seems to be too controversial to be merged. We need to go in a different direction to solve this issue. |
Fixes: #620
R=@bnoordhuis