diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2017-08-26 22:44:07 -0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2017-09-12 17:29:37 -0300 |
commit | 22ae8c02480444b5d09fabeadbac65f54809c206 (patch) | |
tree | 8167763d86c4ec375db8e959432b8266134ed984 /doc/api/assert.md | |
parent | e13d1df89bbaf26601b6c1c8406113b80bb6a95c (diff) | |
download | android-node-v8-22ae8c02480444b5d09fabeadbac65f54809c206.tar.gz android-node-v8-22ae8c02480444b5d09fabeadbac65f54809c206.tar.bz2 android-node-v8-22ae8c02480444b5d09fabeadbac65f54809c206.zip |
assert: fix boxed primitives in deepStrictEqual
Unbox all primitives and compare them as well instead of
only comparing boxed strings.
PR-URL: https://github.com/nodejs/node/pull/15050
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'doc/api/assert.md')
-rw-r--r-- | doc/api/assert.md | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/doc/api/assert.md b/doc/api/assert.md index fd8973efb9..111fd629f7 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -134,7 +134,7 @@ changes: * `expected` {any} * `message` {any} -Generally identical to `assert.deepEqual()` with three exceptions: +Generally identical to `assert.deepEqual()` with a few exceptions: 1. Primitive values besides `NaN` are compared using the [Strict Equality Comparison][] ( `===` ). Set and Map values, Map keys and `NaN` are compared @@ -143,6 +143,7 @@ Generally identical to `assert.deepEqual()` with three exceptions: 2. [`[[Prototype]]`][prototype-spec] of objects are compared using the [Strict Equality Comparison][] too. 3. [Type tags][Object.prototype.toString()] of objects should be the same. +4. [Object wrappers][] are compared both as objects and unwrapped values. ```js const assert = require('assert'); @@ -172,8 +173,14 @@ assert.deepEqual(date, fakeDate); assert.deepStrictEqual(date, fakeDate); // AssertionError: 2017-03-11T14:25:31.849Z deepStrictEqual Date {} // Different type tags + assert.deepStrictEqual(NaN, NaN); // OK, because of the SameValueZero comparison + +assert.deepStrictEqual(new Number(1), new Number(2)); +// Fails because the wrapped number is unwrapped and compared as well. +assert.deepStrictEqual(new String('foo'), Object('foo')); +// OK because the object and the string are identical when unwrapped. ``` If the values are not equal, an `AssertionError` is thrown with a `message` @@ -711,3 +718,4 @@ For more information, see [enumerable "own" properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties [mdn-equality-guide]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness [prototype-spec]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots +[Object wrappers]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript |