-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtest.js
More file actions
46 lines (41 loc) · 1.08 KB
/
test.js
File metadata and controls
46 lines (41 loc) · 1.08 KB
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
import test from "ava"
import { fromPromise, pipe, forEach } from "callbag-basics"
import mapPromise from "./lib"
const fetchUser = name => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
name
})
}, 1000)
})
}
const fetchFriends = user => {
return new Promise((resolve, reject) => {
if (user.name === "janry") {
resolve(["aaa", "bbb"])
} else {
resolve(["aaa"])
}
})
}
test.cb("normal", t => {
fromPromise(fetchUser("janry"))
|> mapPromise(user => fetchFriends(user))
|> forEach(friends => {
t.deepEqual(friends, ["aaa", "bbb"])
t.end()
})
fromPromise(fetchUser("judicy"))
|> mapPromise(user => fetchFriends(user))
|> forEach(friends => {
t.deepEqual(friends, ["aaa"])
t.end()
})
fromPromise(fetchUser("judicy"))
|> mapPromise(user => 123)
|> forEach(friends => {
t.deepEqual(friends, 123)
t.end()
})
})