Fix value check logic for ms arg (#5)
This commit is contained in:
parent
339b0ac5db
commit
1a651607e1
2
index.js
2
index.js
|
@ -9,7 +9,7 @@ class TimeoutError extends Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (promise, ms, fallback) => new Promise((resolve, reject) => {
|
module.exports = (promise, ms, fallback) => new Promise((resolve, reject) => {
|
||||||
if (typeof ms !== 'number' && ms >= 0) {
|
if (typeof ms !== 'number' || ms < 0) {
|
||||||
throw new TypeError('Expected `ms` to be a positive number');
|
throw new TypeError('Expected `ms` to be a positive number');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
test.js
8
test.js
|
@ -9,6 +9,14 @@ test('resolves before timeout', async t => {
|
||||||
t.is(await m(delay(50).then(() => fixture), 200), fixture);
|
t.is(await m(delay(50).then(() => fixture), 200), fixture);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('throws when ms is not number', async t => {
|
||||||
|
await t.throws(m(delay(50), '200'), TypeError);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('throws when ms is negative number', async t => {
|
||||||
|
await t.throws(m(delay(50), -1), TypeError);
|
||||||
|
});
|
||||||
|
|
||||||
test('rejects after timeout', async t => {
|
test('rejects after timeout', async t => {
|
||||||
await t.throws(m(delay(200), 50), m.TimeoutError);
|
await t.throws(m(delay(200), 50), m.TimeoutError);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue