jest-stream-marbles
v1.1.0
Published
Jest extension to test WHATWG Streams with marble syntax
Downloads
3
Maintainers
Readme
jest-stream-marbles
Jest extension to test WHATWG Streams with Marble Syntax
Table of Contents
Install
Use either
yarn add jest-stream-marbles
or
npm install jest-stream-marbles
Usage
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;
}
Contributing
This project is open to feedback and contributions, please open an issue.
jest-stream-marbles
follows the Contributor Covenant Code of Conduct.
See Also
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.
License
MIT © 2021 Konstantin Möllers, see LICENSE.