Skip to content

Commit

Permalink
fix: issues chaijs#85
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jun 2, 2022
1 parent 280b03e commit 2ba9a1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

var type = require('type-detect');
var compareFn = require('default-compare-with-symbol').defaultCompareWithSymbol;
function FakeMap() {
this._key = 'chai/deep-eql__' + Math.random() + Date.now();
}
Expand Down Expand Up @@ -276,7 +277,7 @@ function entriesEqual(leftHandOperand, rightHandOperand, options) {
rightHandOperand.forEach(function gatherEntries(key, value) {
rightHandItems.push([ key, value ]);
});
return iterableEqual(leftHandItems.sort(), rightHandItems.sort(), options);
return iterableEqual(leftHandItems.sort(compareFn), rightHandItems.sort(compareFn), options);
}

/*!
Expand Down Expand Up @@ -428,8 +429,8 @@ function objectEqual(leftHandOperand, rightHandOperand, options) {
rightHandKeys = rightHandKeys.concat(rightHandSymbols);
}
if (leftHandKeys.length && leftHandKeys.length === rightHandKeys.length) {
leftHandKeys.sort();
rightHandKeys.sort();
leftHandKeys.sort(compareFn);
rightHandKeys.sort(compareFn);
if (iterableEqual(leftHandKeys, rightHandKeys) === false) {
return false;
}
Expand All @@ -439,8 +440,8 @@ function objectEqual(leftHandOperand, rightHandOperand, options) {
var leftHandEntries = getIteratorEntries(leftHandOperand);
var rightHandEntries = getIteratorEntries(rightHandOperand);
if (leftHandEntries.length && leftHandEntries.length === rightHandEntries.length) {
leftHandEntries.sort();
rightHandEntries.sort();
leftHandEntries.sort(compareFn);
rightHandEntries.sort(compareFn);
return iterableEqual(leftHandEntries, rightHandEntries, options);
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
}
},
"dependencies": {
"default-compare-with-symbol": "^1.0.1",
"type-detect": "^4.0.0"
},
"devDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ describe('Generic', function () {
var objectB = { [symb]: { [symb]: 'a' } };
assert(eql(objectA, objectB) === false, 'eql(obj, obj) === false');
});

it('issues#85', function () {
var objectA = new URL('https://github.com/');
var objectB = new URL('https://github.com/');
var objectC = new URL('https://github.com/chaijs/deep-eql');
assert(eql(objectA, objectB) === true, 'eql(obj, obj) === true');
assert(eql(objectA, objectC) === false, 'eql(obj, obj) === false');
});
});


Expand Down

0 comments on commit 2ba9a1d

Please sign in to comment.