-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
64 lines (60 loc) · 941 Bytes
/
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
import test from 'node:test'
import chain from './index.mjs'
import {strictEqual} from 'node:assert'
test('empty chain', () => {
strictEqual(chain()(), void 0)
strictEqual(chain()(() => void 0, 1, 2), void 0)
strictEqual(chain()((a, b) => a + b, 1, 2), 3)
})
test('single chain', () => {
let a
strictEqual(chain(
next => {
a = 1
return next() + 1
}
)(() => 2), 3)
strictEqual(a, 1)
})
test('many chains', async () => {
let a, b, c, d
await chain(
next => {
a = 1
return next(2)
},
async (next, v) => {
b = v
},
() => {
c = 3
}
)()
strictEqual(a, 1)
strictEqual(b, 2)
strictEqual(c, undefined)
})
test('combine chains', async () => {
let a, b, c, d
await chain(
chain(
next => {
a = 1
next()
b = 2
}
),
chain(),
chain(
next => {
c = 3
next()
},
() => d = 4
),
)()
strictEqual(a, 1)
strictEqual(b, 2)
strictEqual(c, 3)
strictEqual(d, 4)
})