diff --git a/index.js b/index.js index ddb8b1c..629b868 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ export class TimeoutError extends Error { export default function pTimeout(promise, milliseconds, fallback, options) { let timer; const cancelablePromise = new Promise((resolve, reject) => { - if (typeof milliseconds !== 'number' || milliseconds < 0) { + if (typeof milliseconds !== 'number' || Math.sign(milliseconds) !== 1) { throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``); } diff --git a/test.js b/test.js index ad86baf..c4d172b 100644 --- a/test.js +++ b/test.js @@ -20,6 +20,10 @@ test('throws when milliseconds is negative number', async t => { await t.throwsAsync(pTimeout(delay(50), -1), {instanceOf: TypeError}); }); +test('throws when milliseconds is NaN', async t => { + await t.throwsAsync(pTimeout(delay(50), Number.NaN), {instanceOf: TypeError}); +}); + test('handles milliseconds being `Infinity`', async t => { t.is( await pTimeout(delay(50, {value: fixture}), Number.POSITIVE_INFINITY),