Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ function extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandTyp
case 'Number':
case 'Boolean':
case 'Date':
// If these types are their instance types (e.g. `new Number`) then re-deepEqual against their values
return deepEqual(leftHandOperand.valueOf(), rightHandOperand.valueOf());
// If these types are their instance types (e.g. `new Number`) then re-deepEqual against their values.
// Own enumerable properties are still compared so two instances carrying differing data are not equal.
return deepEqual(leftHandOperand.valueOf(), rightHandOperand.valueOf()) &&
objectEqual(leftHandOperand, rightHandOperand, options);
case 'Promise':
case 'Symbol':
case 'function':
Expand All @@ -238,7 +240,9 @@ function extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandTyp
case 'Array':
return iterableEqual(leftHandOperand, rightHandOperand, options);
case 'RegExp':
return regexpEqual(leftHandOperand, rightHandOperand);
// Own enumerable properties are still compared so two regexes carrying differing data are not equal.
return regexpEqual(leftHandOperand, rightHandOperand) &&
objectEqual(leftHandOperand, rightHandOperand, options);
case 'Generator':
return generatorEqual(leftHandOperand, rightHandOperand, options);
case 'DataView':
Expand Down
40 changes: 40 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ describe('Generic', function () {
assert(eql('x', 'y') === false, 'eql("x", "y") === false');
});

it('returns false for instances with different own enumerable properties', function () {
var strA = new String('x');
strA.foo = 1;
var strB = new String('x');
strB.foo = 2;
assert(eql(strA, strB) === false, 'eql(new String("x") {foo:1}, new String("x") {foo:2}) === false');
});

});

describe('booleans', function () {
Expand Down Expand Up @@ -63,6 +71,14 @@ describe('Generic', function () {
assert(eql(true, Boolean(false)) === false, 'eql(true, Boolean(false)) === false');
});

it('returns false for instances with different own enumerable properties', function () {
var boolA = new Boolean(true);
boolA.foo = 1;
var boolB = new Boolean(true);
boolB.foo = 2;
assert(eql(boolA, boolB) === false, 'eql(new Boolean(true) {foo:1}, new Boolean(true) {foo:2}) === false');
});

});

describe('null', function () {
Expand Down Expand Up @@ -129,6 +145,14 @@ describe('Generic', function () {
'eql(new Number(-Infinity), new Number(+Infinity)) === false');
});

it('returns false for instances with different own enumerable properties', function () {
var numA = new Number(1);
numA.foo = 1;
var numB = new Number(1);
numB.foo = 2;
assert(eql(numA, numB) === false, 'eql(new Number(1) {foo:1}, new Number(1) {foo:2}) === false');
});

});

describe('dates', function () {
Expand All @@ -148,6 +172,14 @@ describe('Generic', function () {
'eql(dateA, new Date(dateA.getTime() + 1)) === false');
});

it('returns false given two dates with different own enumerable properties', function () {
var dateA = new Date(0);
dateA.foo = 1;
var dateB = new Date(0);
dateB.foo = 2;
assert(eql(dateA, dateB) === false, 'eql(new Date(0) {foo:1}, new Date(0) {foo:2}) === false');
});

});

describe('regexp', function () {
Expand All @@ -166,6 +198,14 @@ describe('Generic', function () {
assert(eql(/^/m, /^/i) === false, 'eql(/^/m, /^/i) === false');
});

it('returns false given two regexes with different own enumerable properties', function () {
var regexpA = /x/;
regexpA.foo = 1;
var regexpB = /x/;
regexpB.foo = 2;
assert(eql(regexpA, regexpB) === false, 'eql(/x/ {foo:1}, /x/ {foo:2}) === false');
});

});

describe('empty types', function () {
Expand Down