-
Notifications
You must be signed in to change notification settings - Fork 0
/
reduce.spec.ts
28 lines (22 loc) · 902 Bytes
/
reduce.spec.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
import { C, marbles } from "jest-stream-marbles";
import { reduce } from "../reduce.js";
describe("reduce", () => {
it("should reduce one stream to another by a callback", async () => {
const act = marbles`---${1}-${2}--${3}---|`;
const exp = marbles`---------------------${[7, C]}`;
await expect(act.pipeThrough(reduce((acc, it) => acc + it, 1))).toStream(exp);
});
it("should propagate an error through the stream", async () => {
const act = marbles`---${1}-${2}--x`;
const exp = marbles`--------------x`;
await expect(act.pipeThrough(reduce((acc, it) => acc + it, 1))).toStream(exp);
});
it("should fail the other stream if the reducer throws", async () => {
const cb = () => {
throw undefined;
};
const act = marbles`---${1}-${2}--|`;
const exp = marbles`---x`;
await expect(act.pipeThrough(reduce(cb, 1))).toStream(exp);
});
});