diff --git a/index.js b/index.js index bdedc96..3a0bbc0 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ var isArguments = require('is-arguments'); var is = require('object-is'); var isRegex = require('is-regex'); var flags = require('regexp.prototype.flags'); +var isArray = require('isarray'); function deepEqual(actual, expected, options) { var opts = options || {}; @@ -12,6 +13,12 @@ function deepEqual(actual, expected, options) { return true; } + var actualIsArray = isArray(actual); + var expectedIsArray = isArray(expected); + if (actualIsArray !== expectedIsArray) { + return false; + } + var actualIsRegex = isRegex(actual); var expectedIsRegex = isRegex(expected); if (actualIsRegex || expectedIsRegex) { diff --git a/package.json b/package.json index 614a9ce..4292ab4 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "dependencies": { "is-arguments": "^1.0.4", "is-regex": "^1.0.4", + "isarray": "^2.0.5", "object-is": "^1.0.1", "object-keys": "^1.1.1", "regexp.prototype.flags": "^1.2.0" diff --git a/test/cmp.js b/test/cmp.js index 692ca1d..8805a93 100644 --- a/test/cmp.js +++ b/test/cmp.js @@ -284,11 +284,11 @@ test('regexen', function (t) { }); test('arrays and objects', function (t) { - t.ok(equal([], {}), 'empty array and empty object are equal'); - t.ok(equal({}, []), 'empty object and empty array are equal'); + t.notOk(equal([], {}), 'empty array and empty object are not equal'); + t.notOk(equal({}, []), 'empty object and empty array are not equal'); - t.ok(equal([], {}, { strict: true }), 'strict: empty array and empty object are equal'); - t.ok(equal({}, [], { strict: true }), 'strict: empty object and empty array are equal'); + t.notOk(equal([], {}, { strict: true }), 'strict: empty array and empty object are not equal'); + t.notOk(equal({}, [], { strict: true }), 'strict: empty object and empty array are not equal'); t.notOk(equal([], { length: 0 }), 'empty array and empty arraylike object are not equal'); t.notOk(equal({ length: 0 }, []), 'empty arraylike object and empty array are not equal'); @@ -296,11 +296,11 @@ test('arrays and objects', function (t) { t.notOk(equal([], { length: 0 }, { strict: true }), 'strict: empty array and empty arraylike object are not equal'); t.notOk(equal({ length: 0 }, [], { strict: true }), 'strict: empty arraylike object and empty array are not equal'); - t.ok(equal([1], { 0: 1 }), 'array and object are equal'); - t.ok(equal({ 0: 1 }, [1]), 'object and array are equal'); + t.notOk(equal([1], { 0: 1 }), 'array and object are not equal'); + t.notOk(equal({ 0: 1 }, [1]), 'object and array are not equal'); - t.ok(equal([1], { 0: 1 }, { strict: true }), 'strict: array and object are equal'); - t.ok(equal({ 0: 1 }, [1], { strict: true }), 'strict: object and array are equal'); + t.notOk(equal([1], { 0: 1 }, { strict: true }), 'strict: array and object are not equal'); + t.notOk(equal({ 0: 1 }, [1], { strict: true }), 'strict: object and array are not equal'); t.end(); });