IBM / unexpected-rxjs

Assertions for use with RxJS and Unexpected
Apache License 2.0
2 stars 4 forks source link
assertion assertions expect mocha observable rxjs testing unexpected

unexpected-rxjs

Assertions for use with RxJS and Unexpected

This module is a plugin for the Unexpected assertion library which provides handy assertions against RxJS Observables.

Install

Both rxjs and unexpected are peer dependencies of this module.

$ npm install rxjs@^6 # peer dependency
$ npm install unexpected unexpected-rxjs --save-dev

Usage

Use as an Unexpected plugin in Node.js:

const unexpected = require('unexpected');
const expect = unexpected.clone().use(require('unexpected-rxjs'));

Or using ES modules:

import unexpected from 'unexpected';
import unexpectedRxjs from 'unexpected-rxjs';
const expect = unexpected.clone().use(unexpectedRxjs);

Browser, using globals:

const unexpected = window.weknowhow.expect;
const expect = unexpected.clone().use(window.unexpectedRxjs);

Then:

import {of} from 'rxjs';

describe('contrived example', function() {
  it('should emit "foo"', function() {
    return expect(of('foo', 'bar'), 'to emit values', 'foo', 'bar');
  });
});

Assertions

Note: All assertions return Promise values, so you will want to return expect(/*...*/) (using Mocha) or otherwise use async functions.

Development

Execute npm run build to bundle the project for distribution.

Notes

License

Copyright © 2019 IBM. Licensed Apache-2.0