diff --git a/index.js b/index.js index 6600795..ca46bc7 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ var isDate = require('is-date-object'); var getTime = Date.prototype.getTime; var gPO = Object.getPrototypeOf; +var objToString = Object.prototype.toString; function deepEqual(actual, expected, options) { var opts = options || {}; @@ -60,6 +61,8 @@ function objEquiv(a, b, opts) { // an identical 'prototype' property. if (a.prototype !== b.prototype) { return false; } + if (objToString.call(a) !== objToString.call(b)) { return false; } + if (isArguments(a) !== isArguments(b)) { return false; } var aIsArray = isArray(a); diff --git a/package.json b/package.json index a7a2b7e..7839e80 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "devDependencies": { "@ljharb/eslint-config": "^13.1.1", "eslint": "^5.16.0", + "has-symbols": "^1.0.0", "tape": "^4.11.0" }, "repository": { diff --git a/test/cmp.js b/test/cmp.js index 0e3661b..416f7f4 100644 --- a/test/cmp.js +++ b/test/cmp.js @@ -1,5 +1,6 @@ var test = require('tape'); require('./_tape'); +var hasSymbols = require('has-symbols')(); var equal = require('../'); @@ -374,3 +375,20 @@ test('[[Prototypes]]', { skip: !Object.getPrototypeOf }, function (t) { t.end(); }); + +test('toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (t) { + var o1 = {}; + t.equal(Object.prototype.toString.call(o1), '[object Object]', 'o1: Symbol.toStringTag works'); + + var o2 = {}; + t.equal(Object.prototype.toString.call(o2), '[object Object]', 'o2: original Symbol.toStringTag works'); + + t.deepEqualTest(o1, o2, 'two normal empty objects', true, true); + + o2[Symbol.toStringTag] = 'jifasnif'; + t.equal(Object.prototype.toString.call(o2), '[object jifasnif]', 'o2: modified Symbol.toStringTag works'); + + t.deepEqualTest(o1, o2, 'two normal empty objects with different toStringTags', false, false); + + t.end(); +});