-
Notifications
You must be signed in to change notification settings - Fork 4
/
some.test.js
59 lines (48 loc) · 1.62 KB
/
some.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
'use strict';
const subject = require('./some');
const test = require('ava');
test('catchify.some - resolve and reject', async t => {
const [[error1, error2], [value1, value2]] = await subject([
Promise.resolve(1),
Promise.reject(new Error('2'))
]);
t.is(error1, null);
t.is(error2.message, '2');
t.is(value1, 1);
t.is(value2, null);
});
test('catchify.some - resolve and resolve', async t => {
const [errors, values] = await subject([
Promise.resolve(1),
Promise.resolve(2)
]);
t.deepEqual(errors, [null, null]);
t.deepEqual(values, [1, 2]);
});
test('catchify.some - three promises one rejects', async t => {
const [errors, values] = await subject([
new Promise((resolve, reject) => setTimeout(() => resolve(1), 10)),
new Promise((resolve, reject) => setTimeout(() => resolve(2), 15)),
new Promise((resolve, reject) => setTimeout(() => reject(new Error('3')), 5))
]);
t.deepEqual(errors, [null, null, new Error('3')]);
t.deepEqual(values, [1, 2, null]);
});
test('catchify.some - object with three resolved values', async t => {
const [errors, values] = await subject({
a: Promise.resolve(1),
b: Promise.resolve(2),
c: Promise.resolve(3)
});
t.deepEqual(errors, {a: null, b: null, c: null});
t.deepEqual(values, {a: 1, b: 2, c: 3});
});
test('catchify.some - object with two resolved and one rejected', async t => {
const [errors, values] = await subject({
a: Promise.resolve(1),
b: Promise.reject(new Error('2')),
c: Promise.resolve(3)
});
t.deepEqual(errors, {a: null, b: new Error('2'), c: null});
t.deepEqual(values, {a: 1, b: null, c: 3});
});