From b7d1b1dbe06859f22f12ca349d361092d673b77b Mon Sep 17 00:00:00 2001 From: darthcav Date: Mon, 2 Nov 2015 14:50:25 +0100 Subject: [PATCH] bug fix in assertArray() --- lib/typly.js | 9 ++++++--- package.json | 2 +- test/ArrayTest.js | 12 ++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/typly.js b/lib/typly.js index 3058de9..74dbafe 100644 --- a/lib/typly.js +++ b/lib/typly.js @@ -135,13 +135,16 @@ module.exports = { }, assertArray: function (value, fn) { - if (!this.isArray(value, fn)) + if(arguments.length === 1) { - if(arguments.length === 1) + if(!this.isArray(value)) { throw createTypeError(value, 'Array'); } - else + } + else + { + if (!this.isArray(value, fn)) { throw new TypeError('[tiply] Invalid comparison function or type used in array'); } diff --git a/package.json b/package.json index 2457b0f..55ec26b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "typly", "description": "Generic Javascript type checker", - "version": "0.2.1", + "version": "0.2.2", "author": { "name": "Web Compliance Center", "email": "webcc@fit.fraunhofer.de" diff --git a/test/ArrayTest.js b/test/ArrayTest.js index 7df6a59..203e921 100644 --- a/test/ArrayTest.js +++ b/test/ArrayTest.js @@ -13,6 +13,10 @@ describe("typly#ArrayTest", () => assert(typly.isArray(new Array())); }); it("should return true for integer arrays", () => + { + assert(typly.isArray([4, 8, 66])); + }); + it("should return true for integer arrays", () => { assert(typly.isArray([4, 8, 66], typly.isInteger.bind(typly))); }); @@ -23,6 +27,14 @@ describe("typly#ArrayTest", () => }); describe("#assertArray", () => { + it("should return true for integer arrays", () => + { + assert(typly.assertArray([4, 8, 66])); + }); + it("should return true for integer arrays", () => + { + assert(typly.assertArray([4, 8, 66], typly.isInteger.bind(typly))); + }); it("should throw a TypeError for objects", () => { assert.throws(() =>