-
Notifications
You must be signed in to change notification settings - Fork 14
/
map.test.js
39 lines (34 loc) · 979 Bytes
/
map.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
const map = require("../map")
describe("list/map", () => {
const double = num => num * 2
const asyncDouble = num => Promise.resolve(num).then(double)
function* iterator() {
yield 1
yield 2
yield 3
}
test("sync array", () => {
expect.assertions(1)
const expected = [2, 4, 6]
const actual = map(double)([1, 2, 3])
expect(actual).toMatchObject(expected)
})
test("async array", () => {
expect.assertions(1)
const expected = [2, 4, 6]
const actual = map(asyncDouble)([1, 2, 3])
return expect(actual).resolves.toMatchObject(expected)
})
test("sync iterable", () => {
expect.assertions(1)
const expected = [2, 4, 6]
const actual = map(double)(iterator())
expect(actual).toMatchObject(expected)
})
test("async iterable", () => {
expect.assertions(1)
const expected = [2, 4, 6]
const actual = map(asyncDouble)(iterator())
return expect(actual).resolves.toMatchObject(expected)
})
})