-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.test.ts
63 lines (51 loc) · 1.65 KB
/
merge.test.ts
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
import test from "node:test";
import { ok, equal, deepEqual } from "node:assert/strict";
import Future from "./index.js";
test("merge should accept variable amount of agruments", async () => {
const a = Future.merge(Future.of(""), Future.of(2), Future.of([true]));
return a.then((result) => {
ok(Array.isArray(result));
deepEqual(result, ["", 2, [true]]);
});
});
test("merge should reject if one of futures rejects", async () => {
const a = Future.merge(Future.of(""), Future.fail(2), Future.of([true]));
return a.catch((result) => {
equal(result, 2);
});
});
test("a single array argument should be treated as a list of futures for the merge", async () => {
const a = Future.merge([Future.of(""), Future.of(2), Future.of([true])]);
return a.then((result) => {
deepEqual(result, ["", 2, [true]]);
});
});
test("should treat an arrayLike as non-iterable value", async () => {
const a = Future.merge({
0: Future.of(""),
1: Future.of(2),
2: Future.of([true]),
length: 3,
});
return a.then((result) => {
ok(Array.isArray(result));
equal(result.length, 1);
equal(typeof result[0], "object");
ok("length" in result[0]);
equal(result[0].length, 3);
ok(Future.is(result[0][0]));
ok(Future.is(result[0][1]));
ok(Future.is(result[0][2]));
});
});
test("a single iterable should be treated as a list of futures for the merge", async () => {
const foo = Object.assign(() => {}, {
*[Symbol.iterator]() {
yield* [Future.of(""), Future.of(2), Future.of([true])];
},
});
const a = Future.merge(foo);
return a.then((result) => {
deepEqual(result, ["", 2, [true]]);
});
});