Skip to content

Jest extension to test WHATWG Streams with marble syntax

License

Notifications You must be signed in to change notification settings

ksm2/jest-stream-marbles

Repository files navigation

jest-stream-marbles

Node.js CI NPM version license TypeScript types

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:

License

MIT © 2021 Konstantin Möllers, see LICENSE.