Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eb2bf46

Browse filesBrowse files
Giovanni Bucciaduh95
authored andcommitted
assert: make partialDeepStrictEqual work with urls and File prototypes
PR-URL: #56231 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
1 parent cbbcaf9 commit eb2bf46
Copy full SHA for eb2bf46

File tree

Expand file treeCollapse file tree

3 files changed

+37
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+37
-2
lines changed
Open diff view settings
Collapse file

‎lib/assert.js‎

Copy file name to clipboardExpand all lines: lib/assert.js
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const CallTracker = require('internal/assert/calltracker');
9595
const {
9696
validateFunction,
9797
} = require('internal/validators');
98+
const { isURL } = require('internal/url');
9899

99100
let isDeepEqual;
100101
let isDeepStrictEqual;
@@ -383,7 +384,7 @@ function isSpecial(obj) {
383384
}
384385

385386
const typesToCallDeepStrictEqualWith = [
386-
isKeyObject, isWeakSet, isWeakMap, Buffer.isBuffer, isSharedArrayBuffer,
387+
isKeyObject, isWeakSet, isWeakMap, Buffer.isBuffer, isSharedArrayBuffer, isURL,
387388
];
388389

389390
function partiallyCompareMaps(actual, expected, comparedObjects) {
@@ -466,7 +467,7 @@ function partiallyCompareArrayBuffersOrViews(actual, expected) {
466467
}
467468

468469
for (let i = 0; i < expectedViewLength; i++) {
469-
if (actualView[i] !== expectedView[i]) {
470+
if (!ObjectIs(actualView[i], expectedView[i])) {
470471
return false;
471472
}
472473
}
@@ -586,6 +587,10 @@ function compareBranch(
586587
expected,
587588
comparedObjects,
588589
) {
590+
// Checking for the simplest case possible.
591+
if (actual === expected) {
592+
return true;
593+
}
589594
// Check for Map object equality
590595
if (isMap(actual) && isMap(expected)) {
591596
return partiallyCompareMaps(actual, expected, comparedObjects);
Collapse file

‎test/parallel/test-assert-objects.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert-objects.js
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ describe('Object Comparison Tests', () => {
306306
actual: { dataView: new Uint8Array(3) },
307307
expected: { dataView: new DataView(new ArrayBuffer(3)) },
308308
},
309+
{
310+
description: 'throws when comparing Float32Array([+0.0]) with Float32Array([-0.0])',
311+
actual: new Float32Array([+0.0]),
312+
expected: new Float32Array([-0.0]),
313+
},
314+
{
315+
description: 'throws when comparing two different urls',
316+
actual: new URL('http://foo'),
317+
expected: new URL('http://bar'),
318+
},
309319
{
310320
description: 'throws when comparing SharedArrayBuffers when expected has different elements actual',
311321
actual: (() => {
@@ -778,6 +788,21 @@ describe('Object Comparison Tests', () => {
778788
actual: [1, 2, 3],
779789
expected: [2],
780790
},
791+
{
792+
description: 'ensures that File extends Blob',
793+
actual: Object.getPrototypeOf(File.prototype),
794+
expected: Blob.prototype
795+
},
796+
{
797+
description: 'compares NaN with NaN',
798+
actual: NaN,
799+
expected: NaN,
800+
},
801+
{
802+
description: 'compares two identical urls',
803+
actual: new URL('http://foo'),
804+
expected: new URL('http://foo'),
805+
},
781806
].forEach(({ description, actual, expected }) => {
782807
it(description, () => {
783808
assert.partialDeepStrictEqual(actual, expected);
Collapse file

‎test/parallel/test-assert-typedarray-deepequal.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert-typedarray-deepequal.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,15 @@ suite('notEqualArrayPairs', () => {
101101
makeBlock(assert.deepStrictEqual, arrayPair[0], arrayPair[1]),
102102
assert.AssertionError
103103
);
104+
// TODO(puskin94): remove emitWarning override once the partialDeepStrictEqual method is not experimental anymore
105+
// Suppress warnings, necessary otherwise the tools/pseudo-tty.py runner will fail
106+
const originalEmitWarning = process.emitWarning;
107+
process.emitWarning = () => {};
104108
assert.throws(
105109
makeBlock(assert.partialDeepStrictEqual, arrayPair[0], arrayPair[1]),
106110
assert.AssertionError
107111
);
112+
process.emitWarning = originalEmitWarning; // Restore original process.emitWarning
108113
});
109114
}
110115
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.