-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.js
72 lines (60 loc) · 1.5 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import test from 'ava';
import delay from 'delay';
import timeSpan from 'time-span';
import pTap from './index.js';
const fixture = Symbol('unicorn');
const fixtureError = new Error('unicorn');
const tapError = new Error('tap error!');
test('ignores tap value', async t => {
const value = await Promise.resolve(fixture)
.then(pTap(tapValue => {
t.is(tapValue, fixture);
return 'ignored-val';
}));
t.is(value, fixture);
});
test('does not ignore tap error', async t => {
await Promise.resolve(fixture)
.then(pTap(() => {
throw tapError;
}))
.catch(error => {
t.is(error, tapError);
});
});
test('waits for tap promise to resolve', async t => {
const end = timeSpan();
const value = await Promise.resolve(fixture).then(pTap(() => delay(200)));
t.is(value, fixture);
t.true(end() > 180);
});
test('catch - ignores tap value', async t => {
t.plan(2);
await Promise.reject(fixtureError)
.catch(pTap.catch(error => {
t.is(error, fixtureError);
return 'ignored-val';
}))
.catch(error => {
t.is(error, fixtureError);
});
});
test('catch - does not ignore tap error', async t => {
t.plan(1);
await Promise.reject(fixtureError)
.catch(pTap.catch(() => {
throw tapError;
}))
.catch(error => {
t.is(error, tapError);
});
});
test('catch - waits for tap promise to resolve', async t => {
const end = timeSpan();
await Promise.reject(fixtureError)
.catch(pTap.catch(() => delay(200)))
.catch(error => {
t.is(error, fixtureError);
t.true(end() > 180);
});
});