-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathall.test.js
49 lines (43 loc) · 1.2 KB
/
all.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
'use strict';
const subject = require('./all');
const test = require('ava');
test('catchify.all - two values resolved', async t => {
const [error, [value1, value2]] = await subject([1, 2]);
t.is(error, null);
t.is(value1, 1);
t.is(value2, 2);
});
test('catchify.all - one of three promises rejected', async t => {
const [error, [value1, value2, value3]] = await subject([
Promise.resolve(1),
Promise.resolve(2),
Promise.reject(new Error('3'))
]);
t.is(error.message, '3');
t.is(value1, undefined);
t.is(value2, undefined);
t.is(value3, undefined);
});
test('catchify.all - object with values', async t => {
const [error, {a, b}] = await subject({a: 1, b: 2});
t.is(error, null);
t.is(a, 1);
t.is(b, 2);
});
test('catchify.all - object with promises that both resolve', async t => {
const [error, {a, b}] = await subject({
a: Promise.resolve(1),
b: Promise.resolve(2)
});
t.is(error, null);
t.is(a, 1);
t.is(b, 2);
});
test('catchify.all - object with promises and one rejects', async t => {
const [error, values] = await subject({
a: Promise.resolve(1),
b: Promise.reject(new Error('2'))
});
t.is(error.message, '2');
t.deepEqual(values, {});
});