-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
test.js
39 lines (33 loc) · 1.17 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import test from 'ava';
import delay from 'yoctodelay';
import timeSpan from 'time-span';
import inRange from 'in-range';
import pMinDelay from './index.js';
const fixture = Symbol('fixture');
test('only settles after minimum delay', async t => {
const end = timeSpan();
const result = await pMinDelay(Promise.resolve(fixture), 200);
t.is(result, fixture);
t.true(inRange(end(), {start: 170, end: 230}));
});
test('accept non-promise object', async t => {
const end = timeSpan();
const result = await pMinDelay(fixture, 200);
t.is(result, fixture);
t.true(inRange(end(), {start: 170, end: 230}));
});
test('promise takes longer than minimum delay', async t => {
const end = timeSpan();
await pMinDelay(delay(200), 100);
t.true(inRange(end(), {start: 170, end: 230}));
});
test('minimum delay applies to rejection too', async t => {
const end = timeSpan();
await pMinDelay(Promise.reject(), 100).catch(() => {});
t.true(inRange(end(), {start: 70, end: 130}));
});
test('option - {delayRejection:false}', async t => {
const end = timeSpan();
await pMinDelay(Promise.reject(), 100, {delayRejection: false}).catch(() => {});
t.true(inRange(end(), {start: 0, end: 30}));
});