diff --git a/index.js b/index.js index a1d2ea4..8b3455a 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ module.exports = function(val, options) { var type = typeof val; if (type === 'string' && val.length > 0) { return parse(val); - } else if (type === 'number' && isNaN(val) === false) { + } else if (type === 'number' && isFinite(val)) { return options.long ? fmtLong(val) : fmtShort(val); } throw new Error( diff --git a/tests.js b/tests.js index 9427390..6a44931 100644 --- a/tests.js +++ b/tests.js @@ -283,4 +283,16 @@ describe('ms(invalid inputs)', function() { ms(NaN); }).to.throwError(); }); + + it('should throw an error, when ms(Infinity)', function() { + expect(function() { + ms(Infinity); + }).to.throwError(); + }); + + it('should throw an error, when ms(-Infinity)', function() { + expect(function() { + ms(-Infinity); + }).to.throwError(); + }); });