-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha-simple-chain.test.ts
More file actions
36 lines (29 loc) · 923 Bytes
/
a-simple-chain.test.ts
File metadata and controls
36 lines (29 loc) · 923 Bytes
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
import { consume } from "../../src/consumers";
import { fromIterable } from "../../src/producers";
import { map } from "../../src/transformers";
describe("a simple case", () => {
test("can sum numbers", async () => {
async function* getNumbers() {
yield 1;
yield 2;
yield 3;
}
const addOne = map((x: number) => x + 1);
const spy = jest.fn();
for await (const n of addOne(getNumbers())) {
spy(n);
}
expect(spy).toHaveBeenCalledTimes(3);
expect(spy).toHaveBeenCalledWith(2);
expect(spy).toHaveBeenCalledWith(3);
expect(spy).toHaveBeenCalledWith(4);
});
test("a nicer version", async () => {
const anArray = [1, 2, 3];
const source = fromIterable(anArray);
const addOne = map((x: number) => x + 1);
const results = await consume(addOne(source));
const expectation = [2, 3, 4];
expect(results).toEqual(expectation);
});
});