diff --git a/src/js/util.ts b/src/js/util.ts index 61a28d3..976e6c4 100644 --- a/src/js/util.ts +++ b/src/js/util.ts @@ -92,10 +92,10 @@ export const valueToJsonString = ( */ export const roundToPrecision = (value: number, bit: number = 0): number => { if (!Number.isFinite(value)) { - throw new TypeError(`${value} is not a number.`); + throw new TypeError(`${value} is not a finite number.`); } if (!Number.isFinite(bit)) { - throw new TypeError(`${bit} is not a number.`); + throw new TypeError(`${bit} is not a finite number.`); } else if (bit < 0 || bit > HEX) { throw new RangeError(`${bit} is not between 0 and ${HEX}.`); } @@ -126,10 +126,10 @@ export const interpolateHue = ( arc: string = 'shorter' ): Array => { if (!Number.isFinite(hueA)) { - throw new TypeError(`${hueA} is not a number.`); + throw new TypeError(`${hueA} is not a finite number.`); } if (!Number.isFinite(hueB)) { - throw new TypeError(`${hueB} is not a number.`); + throw new TypeError(`${hueB} is not a finite number.`); } switch (arc) { case 'decreasing': { diff --git a/test/util.test.ts b/test/util.test.ts index 9b8b4a4..31acab8 100644 --- a/test/util.test.ts +++ b/test/util.test.ts @@ -177,14 +177,22 @@ describe('round to specified precision', () => { const func = util.roundToPrecision; it('should throw', () => { - assert.throws(() => func(), TypeError, 'undefined is not a number.'); + assert.throws(() => func(), TypeError, 'undefined is not a finite number.'); + }); + + it('should throw', () => { + assert.throws( + () => func(Infinity), + TypeError, + 'Infinity is not a finite number.' + ); }); it('should throw', () => { assert.throws( () => func(1.23456789, 'foo'), TypeError, - 'foo is not a number.' + 'foo is not a finite number.' ); }); @@ -269,11 +277,15 @@ describe('interpolate hue', () => { const func = util.interpolateHue; it('should throw', () => { - assert.throws(() => func(), TypeError, 'undefined is not a number.'); + assert.throws(() => func(), TypeError, 'undefined is not a finite number.'); }); it('should throw', () => { - assert.throws(() => func(90), TypeError, 'undefined is not a number.'); + assert.throws( + () => func(90), + TypeError, + 'undefined is not a finite number.' + ); }); it('should get value', () => {