diff --git a/index.js b/index.js index 8b65f8f..5387e4e 100644 --- a/index.js +++ b/index.js @@ -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(); } @@ -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); } /*! @@ -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; } @@ -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); } diff --git a/package.json b/package.json index bc2846a..7d7ff70 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ } }, "dependencies": { + "default-compare-with-symbol": "^1.0.1", "type-detect": "^4.0.0" }, "devDependencies": { diff --git a/test/index.js b/test/index.js index 64909e8..de34ea2 100644 --- a/test/index.js +++ b/test/index.js @@ -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'); + }); });