An open API service indexing awesome lists of open source software.

https://github.com/ksm2/jest-stream-marbles

Jest extension to test WHATWG Streams with marble syntax
https://github.com/ksm2/jest-stream-marbles

jest marble-testing streams-api whatwg-streams

Last synced: 12 months ago
JSON representation

Jest extension to test WHATWG Streams with marble syntax

Awesome Lists containing this project

README

          

# jest-stream-marbles

[![Node.js CI](https://github.com/ksm2/jest-stream-marbles/actions/workflows/node.js.yml/badge.svg)](https://github.com/ksm2/jest-stream-marbles/actions/workflows/node.js.yml)
[![NPM version](https://img.shields.io/npm/v/jest-stream-marbles)](https://www.npmjs.com/package/jest-stream-marbles)
[![license](https://img.shields.io/github/license/ksm2/jest-stream-marbles)](https://opensource.org/licenses/MIT)
![TypeScript types](https://img.shields.io/npm/types/jest-stream-marbles)

> Jest extension to test [WHATWG Streams] with [Marble Syntax]

## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [Contributing](#contributing)
- [See Also](#see-also)
- [License](#license)

## 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.

```js
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](https://github.com/ksm2/jest-stream-marbles/issues).

`jest-stream-marbles` follows the [Contributor Covenant] Code of Conduct.

## See Also

Also have a look at the following NPM Packages:

- [isomorphic-streams](https://github.com/ksm2/isomorphic-streams) - Isomorphic package for WHATWG Streams in Node.js and the browser.
- [stream-transformers](https://github.com/ksm2/stream-transformers) - Reusable stream transformers similar to ReactiveX Operators.

## License

MIT © 2021 Konstantin Möllers, see [LICENSE].

[whatwg streams]: https://streams.spec.whatwg.org/
[marble syntax]: https://rxjs.dev/guide/testing/marble-testing
[license]: https://github.com/ksm2/jest-stream-marbles/blob/main/LICENSE
[contributor covenant]: https://github.com/ksm2/jest-stream-marbles/blob/main/CODE_OF_CONDUCT.md