Improved error message thrown in inRange, added additional test cases for inRange
This commit is contained in:
parent
585700dffb
commit
48a3b391c1
2 changed files with 12 additions and 1 deletions
5
index.js
5
index.js
|
|
@ -1,4 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const util = require('util');
|
||||||
|
|
||||||
const toString = Object.prototype.toString;
|
const toString = Object.prototype.toString;
|
||||||
const getObjectType = x => toString.call(x).slice(8, -1);
|
const getObjectType = x => toString.call(x).slice(8, -1);
|
||||||
const isOfType = type => x => typeof x === type; // eslint-disable-line valid-typeof
|
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);
|
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;
|
module.exports = is;
|
||||||
|
|
|
||||||
8
test.js
8
test.js
|
|
@ -332,7 +332,15 @@ test('is.inRange', t => {
|
||||||
m.inRange(0);
|
m.inRange(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
t.throws(() => {
|
||||||
|
m.inRange(0, []);
|
||||||
|
});
|
||||||
|
|
||||||
t.throws(() => {
|
t.throws(() => {
|
||||||
m.inRange(0, [5]);
|
m.inRange(0, [5]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
t.throws(() => {
|
||||||
|
m.inRange(0, [1, 2, 3]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue