| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1789dcf commit ea2e636
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,6 +107,9 @@ parameter is undefined, a default error message is assigned. | |||
| 107 | 107 | <!-- YAML | |
| 108 | 108 | added: v1.2.0 | |
| 109 | 109 | changes: | |
| 110 | + - version: REPLACEME | ||
| 111 | + pr-url: https://github.com/nodejs/node/pull/15036 | ||
| 112 | + description: NaN is now compared using the [SameValueZero][] comparison. | ||
| 110 | 113 | - version: REPLACEME | |
| 111 | 114 | pr-url: https://github.com/nodejs/node/pull/15001 | |
| 112 | 115 | description: Error names and messages are now properly compared | |
@@ -129,9 +132,10 @@ changes: | |||
| 129 | 132 | ||
| 130 | 133 | Generally identical to `assert.deepEqual()` with three exceptions: | |
| 131 | 134 | ||
| 132 | - 1. Primitive values are compared using the [Strict Equality Comparison][] | ||
| 133 | - ( `===` ). Set values and Map keys are compared using the [SameValueZero][] | ||
| 134 | - comparison. (Which means they are free of the [caveats][]). | ||
| 135 | + 1. Primitive values besides `NaN` are compared using the [Strict Equality | ||
| 136 | + Comparison][] ( `===` ). Set and Map values, Map keys and `NaN` are compared | ||
| 137 | + using the [SameValueZero][] comparison (which means they are free of the | ||
| 138 | + [caveats][]). | ||
| 135 | 139 | 2. [`[[Prototype]]`][prototype-spec] of objects are compared using | |
| 136 | 140 | the [Strict Equality Comparison][] too. | |
| 137 | 141 | 3. [Type tags][Object.prototype.toString()] of objects should be the same. | |
@@ -164,6 +168,8 @@ assert.deepEqual(date, fakeDate); | |||
| 164 | 168 | assert.deepStrictEqual(date, fakeDate); | |
| 165 | 169 | // AssertionError: 2017-03-11T14:25:31.849Z deepStrictEqual Date {} | |
| 166 | 170 | // Different type tags | |
| 171 | + assert.deepStrictEqual(NaN, NaN); | ||
| 172 | + // OK, because of the SameValueZero comparison | ||
| 167 | 173 | ``` | |
| 168 | 174 | ||
| 169 | 175 | If the values are not equal, an `AssertionError` is thrown with a `message` | |
@@ -412,6 +418,9 @@ parameter is undefined, a default error message is assigned. | |||
| 412 | 418 | <!-- YAML | |
| 413 | 419 | added: v1.2.0 | |
| 414 | 420 | changes: | |
| 421 | + - version: REPLACEME | ||
| 422 | + pr-url: https://github.com/nodejs/node/pull/15036 | ||
| 423 | + description: NaN is now compared using the [SameValueZero][] comparison. | ||
| 415 | 424 | - version: REPLACEME | |
| 416 | 425 | pr-url: https://github.com/nodejs/node/pull/15001 | |
| 417 | 426 | description: Error names and messages are now properly compared | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -167,8 +167,11 @@ function isObjectOrArrayTag(tag) { | |||
| 167 | 167 | // a) The same built-in type tags | |
| 168 | 168 | // b) The same prototypes. | |
| 169 | 169 | function strictDeepEqual(actual, expected) { | |
| 170 | - if (actual === null || expected === null || | ||
| 171 | - typeof actual !== 'object' || typeof expected !== 'object') { | ||
| 170 | + if (typeof actual !== 'object') { | ||
| 171 | + return typeof actual === 'number' && Number.isNaN(actual) && | ||
| 172 | + Number.isNaN(expected); | ||
| 173 | + } | ||
| 174 | + if (typeof expected !== 'object' || actual === null || expected === null) { | ||
| 172 | 175 | return false; | |
| 173 | 176 | } | |
| 174 | 177 | const actualTag = objectToString(actual); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -466,6 +466,7 @@ assertOnlyDeepEqual( | |||
| 466 | 466 | assertDeepAndStrictEqual(m3, m4); | |
| 467 | 467 | } | |
| 468 | 468 | ||
| 469 | + // Handle sparse arrays | ||
| 469 | 470 | assertDeepAndStrictEqual([1, , , 3], [1, , , 3]); | |
| 470 | 471 | assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]); | |
| 471 | 472 | ||
@@ -481,4 +482,11 @@ assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]); | |||
| 481 | 482 | assertOnlyDeepEqual(err1, {}, assert.AssertionError); | |
| 482 | 483 | } | |
| 483 | 484 | ||
| 485 | + // Handle NaN | ||
| 486 | + assert.throws(() => { assert.deepEqual(NaN, NaN); }, assert.AssertionError); | ||
| 487 | + assert.doesNotThrow(() => { assert.deepStrictEqual(NaN, NaN); }); | ||
| 488 | + assert.doesNotThrow(() => { assert.deepStrictEqual({ a: NaN }, { a: NaN }); }); | ||
| 489 | + assert.doesNotThrow( | ||
| 490 | + () => { assert.deepStrictEqual([ 1, 2, NaN, 4 ], [ 1, 2, NaN, 4 ]); }); | ||
| 491 | + | ||
| 484 | 492 | /* eslint-enable */ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments