Code Monkey home page Code Monkey logo

rx-assert's Introduction

rx-assert

Helper methods for making asserts in unit tests for rxjs library.

Installation

npm install rx-assert

Description

This package provides a low level api for comparing observable sequences. Can be used in unit tests for comparing observables.
Here is the wrapper around this library to use it as chai plugin - chai-rx-assert

Example:

const rxAssert = require('rx-assert');

const assert = require('chai').assert;

const Rx = require('rx');
const TestScheduler = Rx.TestScheduler;
const onNext = Rx.ReactiveTest.onNext;
const onError = Rx.ReactiveTest.onError;
const onCompleted = Rx.ReactiveTest.onCompleted;
const subscribe = Rx.ReactiveTest.subscribe;

describe('getDelayedStream', () => {
    
    it('should return messages with delay', () => {
        const scheduler = new TestScheduler();

        const xs = scheduler.createHotObservable(
            onNext(150, 1),
            onNext(250, 2),
            onNext(350, 3),
            onNext(450, 4),
            onCompleted(550)
        );

        const results = scheduler.startScheduler(() => {
            return xs.delay(100, scheduler);
        });

        const expected = [
            onNext(350, 2),
            onNext(450, 3),
            onNext(550, 4),
            onCompleted(650)
        ]

        const [equal, message] = rxAssert.isEqual(results.messages, expected);

        assert.isOk(equal, message)
    });
});

Methods

isEqual(actual, expected)

  • @param {List} actual List with notification records (onNext(), onCompleted e.t.c)
  • @param {List} expected List with notification records (onNext(), onCompleted e.t.c)
  • @return {List} List with 2 elements - [isEqual {bool}, diffMessage {String}]

First element defines wether actual and expected sequences are equal.
The second one provides a diff message.

Example:

const xs = scheduler.createHotObservable(
    onNext(150, 1),
    onNext(250, 2),
    onNext(350, 3),
    onNext(450, 4),
    onCompleted(550)
);

const results = scheduler.startScheduler(() => {
    return xs.delay(100, scheduler);
});

const expected = [
    onNext(350, 2),
    onNext(450, 3),
    onNext(550, 4),
    onCompleted(650)
]

const [equal, message] = rxAssert.isEqual(results.messages, expected);

Dev info

Installation

git clone
cd
npm install .

Test coverage

Contributions are welcome. Dont forget to check the tests.

npm test

rx-assert's People

Contributors

alexmost avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.