diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-12-02 13:02:48 +0100 |
---|---|---|
committer | Beth Griggs <Bethany.Griggs@uk.ibm.com> | 2020-02-06 02:49:27 +0000 |
commit | a0f338ecc1df843dc221d4cd0ceae0af569af41a (patch) | |
tree | d0c86411b7ff18cdd998d60d9c047b3cac28ca3b /test | |
parent | 6a5580299e6fe2cfb413f36d7541203d8f676454 (diff) | |
download | node-new-a0f338ecc1df843dc221d4cd0ceae0af569af41a.tar.gz |
assert,util: stricter type comparison using deep equal comparisons
This veryfies that both input arguments are always of the identical
type. It was possible to miss a few cases before. This change applies
to all deep equal assert functions (e.g., `assert.deepStrictEqual()`)
and to `util.isDeepStrictEqual()`.
PR-URL: https://github.com/nodejs/node/pull/30764
Refs: https://github.com/nodejs/node/pull/30743
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-assert-deep.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index 4f928bf4a0..92e04634dc 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -1138,3 +1138,69 @@ assert.throws( // The descriptor is not compared. assertDeepAndStrictEqual(a, { a: 5 }); } + +// Verify object types being identical on both sides. +{ + let a = Buffer.from('test'); + let b = Object.create( + Object.getPrototypeOf(a), + Object.getOwnPropertyDescriptors(a) + ); + Object.defineProperty(b, Symbol.toStringTag, { + value: 'Uint8Array' + }); + assertNotDeepOrStrict(a, b); + + a = new Uint8Array(10); + b = new Int8Array(10); + Object.defineProperty(b, Symbol.toStringTag, { + value: 'Uint8Array' + }); + Object.setPrototypeOf(b, Uint8Array.prototype); + assertNotDeepOrStrict(a, b); + + a = [1, 2, 3]; + b = { 0: 1, 1: 2, 2: 3 }; + Object.setPrototypeOf(b, Array.prototype); + Object.defineProperty(b, 'length', { value: 3, enumerable: false }); + Object.defineProperty(b, Symbol.toStringTag, { + value: 'Array' + }); + assertNotDeepOrStrict(a, b); + + a = new Date(2000); + b = Object.create( + Object.getPrototypeOf(a), + Object.getOwnPropertyDescriptors(a) + ); + Object.defineProperty(b, Symbol.toStringTag, { + value: 'Date' + }); + assertNotDeepOrStrict(a, b); + + a = /abc/g; + b = Object.create( + Object.getPrototypeOf(a), + Object.getOwnPropertyDescriptors(a) + ); + Object.defineProperty(b, Symbol.toStringTag, { + value: 'RegExp' + }); + assertNotDeepOrStrict(a, b); + + a = []; + b = /abc/; + Object.setPrototypeOf(b, Array.prototype); + Object.defineProperty(b, Symbol.toStringTag, { + value: 'Array' + }); + assertNotDeepOrStrict(a, b); + + a = Object.create(null); + b = new RangeError('abc'); + Object.defineProperty(a, Symbol.toStringTag, { + value: 'Error' + }); + Object.setPrototypeOf(b, null); + assertNotDeepOrStrict(a, b, assert.AssertionError); +} |