From 48a3b391c1112e7799f3ea1ecbde6bd1936c51db Mon Sep 17 00:00:00 2001 From: Giora Guttsait Date: Wed, 27 Sep 2017 10:59:13 +0300 Subject: [PATCH] Improved error message thrown in `inRange`, added additional test cases for `inRange` --- index.js | 5 ++++- test.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index aba0646..552481d 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,7 @@ 'use strict'; + +const util = require('util'); + const toString = Object.prototype.toString; const getObjectType = x => toString.call(x).slice(8, -1); const isOfType = type => x => typeof x === type; // eslint-disable-line valid-typeof @@ -151,7 +154,7 @@ is.inRange = (x, range) => { return x >= Math.min.apply(null, range) && x <= Math.max.apply(null, range); } - throw new TypeError('Invalid range'); + throw new TypeError(`Invalid range: ${util.inspect}`); }; module.exports = is; diff --git a/test.js b/test.js index 4a6bf4e..316bb41 100644 --- a/test.js +++ b/test.js @@ -332,7 +332,15 @@ test('is.inRange', t => { m.inRange(0); }); + t.throws(() => { + m.inRange(0, []); + }); + t.throws(() => { m.inRange(0, [5]); }); + + t.throws(() => { + m.inRange(0, [1, 2, 3]); + }); });