-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: introduce deepStrictEqual
#639
Conversation
3b56e2d
to
6a73421
Compare
deepStictEqual
deepStrictEqual
There was a large discussion in IRC a couple weeks ago on why this didn't make semantic sense. Basically strict and deep are mutually exclusive; having them both together means having a While such a structure can still be useful, I'm not sure if it is actually good. |
What about primitives? Think about if you're trying to do a |
Why? I don't get it. |
See the conversation following: http://logs.libuv.org/io.js/2014-12-15#19:43:36.553 I'll re-read the conversation again tonight as I would like this kind of feature. |
what I want is feedback from people. I personally expect asserts to be as strict as possible in tests |
// if one is a primitive, the other must be same | ||
if (util.isPrimitive(a) || util.isPrimitive(b)) | ||
return a === b; | ||
if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) | ||
return false; |
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.
This is still going to suffer from the things discussed in #621
Are we sure this shouldn't just check primitives? Otherwise we might as well just do a regular strictEquals()
.
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.
not sure what you mean. recursively call deepStrictEqual
on prototypes?
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.
Looked at the tests and it seems as I would expect. I think I mis-understood points made in the previous thread.
LGTM |
Ok, so the PR has been approved by TC. I'm not sure it's ok to merge it now since we don't have a branch for next minor release and I don't know if want to do 1.2.0 right after 1.1.0 /cc @chrisdickinson |
6a73421
to
147acd6
Compare
rebased the PR. can anyone take a final look? @bnoordhuis maybe |
toString: function() { return this.first + ' ' + this.last; } | ||
}; | ||
|
||
function nameBuilder(first, last) { |
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.
Shouldn't constructor name start with an uppercase letter?
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.
to be honest, I just copied all the test for deepEqual
and changed doesNotThrow
to throws
and vice versa where appropriate. This test doesn't make much sense, but I decided not to remove anything.
Except for the naming thing in the test, it LGTM. |
147acd6
to
a45a104
Compare
tweaked tests to make a bit more sense and removed copy-paste artifacts |
@@ -23,11 +23,12 @@ Tests shallow, coercive non-equality with the not equal comparison operator ( `! | |||
|
|||
## assert.deepEqual(actual, expected[, message]) | |||
|
|||
Tests for deep equality. | |||
Tests for deep equality. Primitive values are compared with the equal comparison operator ( `==` ). |
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.
Can you make lines wrap at 80 columns?
a45a104
to
c91cec8
Compare
assert.throws(makeBlock(a.deepStrictEqual, new String('a'), ['a']), a.AssertionError); | ||
assert.throws(makeBlock(a.deepStrictEqual, new String('a'), {0: 'a'}), a.AssertionError); | ||
assert.throws(makeBlock(a.deepStrictEqual, new Number(1), {}), a.AssertionError); | ||
assert.throws(makeBlock(a.deepStrictEqual, new Boolean(true), {}), 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.
Can you fix the long lines in this file?
`deepStrictEqual` works the same way as `strictEqual`, but uses `===` to compare primitives and requires prototypes of equal objects to be the same object. Fixes: nodejs/node-v0.x-archive#7161
c91cec8
to
fc2bbe5
Compare
@bnoordhuis Wrapped some lines, reworked weird test to just compare arrays and added some tests for primitives. PTAL |
just land it @vkurchatkin, it'll hit 1.2.0 and I think we have reached a point of acceptance on this (re TC meeting specifically). lgtm from me |
`deepStrictEqual` works the same way as `strictEqual`, but uses `===` to compare primitives and requires prototypes of equal objects to be the same object. Fixes: nodejs/node-v0.x-archive#7161 Fixes: #620 PR-URL: #639 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-by: Rod Vagg <[email protected]>
landed in 3f473ef |
Notable changes: * stream: - Simpler stream construction, see nodejs/readable-stream#102 for details. This extends the streams base objects to make their constructors accept default implementation methods, reducing the boilerplate required to implement custom streams. An updated version of readable-stream will eventually be released to match this change in core. (@sonewman) * dns: - `lookup()` now supports an `'all'` boolean option, default to `false` but when turned on will cause the method to return an array of *all* resolved names for an address, see, #744 (@silverwind) * assert: - Remove `prototype` property comparison in `deepEqual()`, considered a bugfix, see #636 (@vkurchatkin) - Introduce a `deepStrictEqual()` method to mirror `deepEqual()` but performs strict equality checks on primitives, see #639 (@vkurchatkin) * **tracing**: - Add LTTng (Linux Trace Toolkit Next Generation) when compiled with the `--with-lttng` option. Trace points match those available for DTrace and ETW. #702 (@thekemkid) * npm upgrade to 2.5.1 * **libuv** upgrade to 1.4.0 * Add new collaborators: - Aleksey Smolenchuk (@lxe) - Shigeki Ohtsu (@shigeki)
deepStrictEqual
works the same way asstrictEqual
, but uses===
to compare primitives and requires prototypes of equal objects to be the same object.Fixes: nodejs/node-v0.x-archive#7161
R=@iojs/collaborators