Jest extension to test WHATWG Streams with Marble Syntax
Use either
yarn add jest-stream-marbles
or
npm install jest-stream-marbles
This module allows you to test WHATWG Streams with Marble Syntax in Jest.
import { marbles } from "jest-stream-marbles";
import { filter } from "stream-transformers";
describe("filter", () => {
it("should filter a stream by a predicate", async () => {
const act = marbles`---${1}-${2}--${3}-${4}---|`;
const exp = marbles`--------${2}-------${4}---|`;
await expect(act.pipeThrough(filter(isEven))).toStream(exp);
});
it("should fail the other stream", async () => {
const act = marbles`---${1}-${2}--x`;
const exp = marbles`--------${2}--x`;
await expect(act.pipeThrough(filter(isEven))).toStream(exp);
});
});
function isEven(num: number): boolean {
return num % 2 === 0;
}
This project is open to feedback and contributions, please open an issue.
jest-stream-marbles
follows the Contributor Covenant Code of Conduct.
Also have a look at the following NPM Packages:
- isomorphic-streams - Isomorphic package for WHATWG Streams in Node.js and the browser.
- stream-transformers - Reusable stream transformers similar to ReactiveX Operators.
MIT © 2021 Konstantin Möllers, see LICENSE.