From 0aba472b36c022836d6860d31bc629dbf0c05b0b Mon Sep 17 00:00:00 2001 From: David Von Lehman Date: Thu, 16 Jul 2015 10:24:24 -0700 Subject: [PATCH] Fix bug in noDifferences function to ensure that lengths of array are equal. --- index.js | 3 +++ package.json | 2 +- test/assert.js | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 89f03c0..d40bd6f 100644 --- a/index.js +++ b/index.js @@ -44,6 +44,9 @@ assert.noDifferences = function(array, otherArray) { if (!(_.isArray(array) && _.isArray(otherArray))) throw new Error("Both arguments must be arrays"); + if (array.length !== otherArray.length) + throw new assert.AssertionError({message: "Arrays are not the same length"}); + if (_.difference(array, otherArray).length > 0) throw new assert.AssertionError({message: "Arrays have differences"}); }; diff --git a/package.json b/package.json index 3460b0d..f6ea404 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dash-assert", - "version": "1.0.2", + "version": "1.0.3", "description": "Assertion wrapper around lodash", "main": "index.js", "keywords": [ diff --git a/test/assert.js b/test/assert.js index 01cc2b9..6456460 100644 --- a/test/assert.js +++ b/test/assert.js @@ -63,6 +63,10 @@ describe('dash-assert', function() { assert.throws(function() { assert.noDifferences([1, 2, 3], [2, 3, 4]); }); + + assert.throws(function() { + assert.noDifferences([], [1, 2, 3]); + }); }); it('hasIntersect', function() {