Skip to content

Commit 40e6cba

Browse files
committed
assert: make partialDeepStrictEqual work with urls and File prototypes
1 parent a1d980c commit 40e6cba

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/assert.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const CallTracker = require('internal/assert/calltracker');
9494
const {
9595
validateFunction,
9696
} = require('internal/validators');
97+
const { isURL } = require('internal/url');
9798

9899
let isDeepEqual;
99100
let isDeepStrictEqual;
@@ -382,7 +383,7 @@ function isSpecial(obj) {
382383
}
383384

384385
const typesToCallDeepStrictEqualWith = [
385-
isKeyObject, isWeakSet, isWeakMap, Buffer.isBuffer, isSharedArrayBuffer,
386+
isKeyObject, isWeakSet, isWeakMap, Buffer.isBuffer, isSharedArrayBuffer, isURL,
386387
];
387388

388389
function partiallyCompareMaps(actual, expected, comparedObjects) {
@@ -465,7 +466,7 @@ function partiallyCompareArrayBuffersOrViews(actual, expected) {
465466
}
466467

467468
for (let i = 0; i < expectedViewLength; i++) {
468-
if (actualView[i] !== expectedView[i]) {
469+
if (!ObjectIs(actualView[i], expectedView[i])) {
469470
return false;
470471
}
471472
}
@@ -555,6 +556,10 @@ function compareBranch(
555556
expected,
556557
comparedObjects,
557558
) {
559+
// Checking for the simplest case possible.
560+
if (actual === expected) {
561+
return true;
562+
}
558563
// Check for Map object equality
559564
if (isMap(actual) && isMap(expected)) {
560565
return partiallyCompareMaps(actual, expected, comparedObjects);

test/parallel/test-assert-objects.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ describe('Object Comparison Tests', () => {
271271
actual: { dataView: new Uint8Array(3) },
272272
expected: { dataView: new DataView(new ArrayBuffer(3)) },
273273
},
274+
{
275+
describe: 'throws when comparing Float32Array([+0.0]) with Float32Array([-0.0])',
276+
actual: new Float32Array([+0.0]),
277+
expected: new Float32Array([-0.0]),
278+
},
279+
{
280+
description: 'throws when comparing two different urls',
281+
actual: new URL('http://foo'),
282+
expected: new URL('http://bar'),
283+
},
274284
{
275285
description: 'throws when comparing SharedArrayBuffers when expected has different elements actual',
276286
actual: (() => {
@@ -728,6 +738,21 @@ describe('Object Comparison Tests', () => {
728738
actual: [1, 2, 3],
729739
expected: [2],
730740
},
741+
{
742+
description: 'ensures that File extends Blob',
743+
actual: Object.getPrototypeOf(File.prototype),
744+
expected: Blob.prototype
745+
},
746+
{
747+
description: 'compares NaN with NaN',
748+
actual: NaN,
749+
expected: NaN,
750+
},
751+
{
752+
description: 'compares two identical urls',
753+
actual: new URL('http://foo'),
754+
expected: new URL('http://foo'),
755+
},
731756
].forEach(({ description, actual, expected }) => {
732757
it(description, () => {
733758
assert.partialDeepStrictEqual(actual, expected);

0 commit comments

Comments
 (0)