GeezerVison is showing github.com — assert: fix loose deepEqual arrays with undefined and null failing · nodejs/node@180778f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/util/comparisons.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -978,9 +978,10 @@ function objEquiv(a, b, mode, keys1, keys2, memos, iterationType) { | 978 | 978 | if (b[i] === undefined) { | 979 | 979 | if (!hasOwn(b, i)) | 980 | 980 | return sparseArrayEquiv(a, b, mode, memos, i); | 981 | | - if (a[i] !== undefined || !hasOwn(a, i)) | | 981 | + if ((a[i] !== undefined || !hasOwn(a, i)) && (mode !== kLoose || a[i] !== null)) | 982 | 982 | return false; | 983 | | - } else if (a[i] === undefined || !innerDeepEqual(a[i], b[i], mode, memos)) { | | 983 | + } else if ((a[i] === undefined || !innerDeepEqual(a[i], b[i], mode, memos)) && | | 984 | + (mode !== kLoose || b[i] !== null)) { | 984 | 985 | return false; | 985 | 986 | } | 986 | 987 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-assert-deep.js +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -126,6 +126,11 @@ test('deepEqual', () => { | 126 | 126 | } | 127 | 127 | }); | 128 | 128 |
| | 129 | +test('loose deepEqual', () => { | | 130 | + assertOnlyDeepEqual([null, undefined, undefined], [null, undefined, null]); | | 131 | + assertNotDeepOrStrict([null, undefined, undefined, 1], [null, undefined, null, 2]); | | 132 | +}); | | 133 | + | 129 | 134 | test('date', () => { | 130 | 135 | assertNotDeepOrStrict(date, date2); | 131 | 136 | assert.throws( | @@ -246,6 +251,13 @@ function assertOnlyDeepEqual(a, b, err) { | 246 | 251 | () => assert.deepStrictEqual(b, a), | 247 | 252 | err || { code: 'ERR_ASSERTION' } | 248 | 253 | ); | | 254 | + | | 255 | + const partial = mustCall(() => { | | 256 | + assert.partialDeepStrictEqual(b, a); | | 257 | + assert.partialDeepStrictEqual(a, b); | | 258 | + }); | | 259 | + | | 260 | + assert.throws(partial, err || { code: 'ERR_ASSERTION' }); | 249 | 261 | } | 250 | 262 |
| 251 | 263 | test('es6 Maps and Sets', () => { | |
|