Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
assert: check object prototype in deepEqual#621
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
test/parallel/test-assert.js Outdated
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.
bnoordhuis commented Jan 27, 2015
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? |
vkurchatkin commented Jan 27, 2015
@bnoordhuis updated. I labeled this PR as |
bnoordhuis commented Jan 27, 2015
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#620evanlucas commented Jan 27, 2015
I'm +1 on this. |
indutny commented Jan 27, 2015
LGTM |
1 similar comment
cjihrig commented Jan 27, 2015
LGTM |
seishun commented Jan 27, 2015
I'm not so sure, people might expect this to be CommonJS compliant, even though the spec is horribly broken (and |
rvagg commented Jan 27, 2015
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. |
rvagg commented Jan 27, 2015
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. |
neumino commented Jan 27, 2015
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. |
bevacqua commented Jan 27, 2015
+1 to what @neumino said. Prototype equality means that you can't compare a model object with a plain JS object for quick assertions |
thlorenz commented Jan 28, 2015
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 |
aheckmann commented Jan 28, 2015
-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. |
thlorenz commented Jan 28, 2015
Do we actually have a way to test at least how many modules/tests on npm would break with this change? |
jonathanong commented Jan 28, 2015
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. |
vkurchatkin commented Jan 28, 2015
as a non-breaking alternative: introduce |
Fishrock123 commented Jan 28, 2015
The problem is that deep and strict are mutually exclusive conceptually. +1 to |
meandmycode commented Jan 28, 2015
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'. |
cjohansen commented Jan 28, 2015
To fill the void, you could add a function like referee's assert.match (although with less flexibility/confusing amounts of input types) - |
vkurchatkin commented Jan 28, 2015
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