-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtest.js
96 lines (84 loc) · 1.46 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import test from 'ava';
import delay from 'delay';
import pProps from './index.js';
test('main', async t => {
t.deepEqual(
await pProps({
foo: delay(100).then(() => 1),
bar: Promise.resolve(2),
faz: 3,
}),
{
foo: 1,
bar: 2,
faz: 3,
},
);
});
test('`Map` input', async t => {
t.deepEqual(
await pProps(new Map([
['foo', Promise.resolve(1)],
['bar', 2],
])),
new Map([
['foo', 1],
['bar', 2],
]),
);
});
test('rejects if any of the input promises reject', async t => {
await t.throwsAsync(
pProps({
foo: Promise.resolve(1),
bar: Promise.reject(new Error('bar')),
}),
{message: 'bar'},
);
});
test('handles empty object', async t => {
t.deepEqual(await pProps({}), {});
t.deepEqual((await pProps(new Map([]))), new Map([]));
});
test('with mapper', async t => {
t.plan(3);
t.deepEqual(
await pProps({
foo: 1,
baz: Promise.resolve(2),
}, async (value, key) => {
if (key === 'foo') {
t.is(value, 1);
}
if (key === 'baz') {
t.is(value, 2);
}
return key + value;
}),
{
foo: 'foo1',
baz: 'baz2',
},
);
});
test('`Map` input with mapper', async t => {
t.plan(3);
t.deepEqual(
await pProps(new Map([
['foo', 1],
['bar', Promise.resolve(2)],
]), async (value, key) => {
if (key === 'foo') {
t.is(value, 1);
}
if (key === 'bar') {
t.is(value, 2);
}
return key + value;
}),
new Map([
['foo', 'foo1'],
['bar', 'bar2'],
]),
);
});