Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support error in case of Infinity #116

Merged
merged 2 commits into from Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions tests.js
Expand Up @@ -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();
});
});