-
Notifications
You must be signed in to change notification settings - Fork 0
/
every.spec.ts
39 lines (30 loc) · 1.21 KB
/
every.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
29
30
31
32
33
34
35
36
37
38
39
import { C, marbles } from "jest-stream-marbles";
import { every } from "../every.js";
describe("every", () => {
it("should return false as soon as the predicate fails", async () => {
const act = marbles`---${1}-${2}--${3}-${4}---|`;
const exp = marbles`--------------${[false, C]}`;
await expect(act.pipeThrough(every(isLessThanThree))).toStream(exp);
});
it("should return true when the stream completes", async () => {
const act = marbles`---${1}-${2}--${1}-${2}---|`;
const exp = marbles`--------------------------${[true, C]}`;
await expect(act.pipeThrough(every(isLessThanThree))).toStream(exp);
});
it("should propagate an error through the stream", async () => {
const act = marbles`---${1}-${2}--${1}-${2}---x`;
const exp = marbles`--------------------------x`;
await expect(act.pipeThrough(every(isLessThanThree))).toStream(exp);
});
it("should fail the other stream if the predicate throws", async () => {
const cb = () => {
throw undefined;
};
const act = marbles`---${1}-${2}--|`;
const exp = marbles`---x`;
await expect(act.pipeThrough(every(cb))).toStream(exp);
});
});
function isLessThanThree(num: number): boolean {
return num < 3;
}