UNPKG

cyclejs-stream

Version:

Observable (events stream) to which you can inject another streams.

135 lines (97 loc) 3.29 kB
/* global suite, test, setup, teardown */ import { assert } from 'chai'; import { Rx } from '@cycle/core'; import InputProxy from '../src/input-proxy'; suite('InputProxy', () => { test('should be a class', () => { assert.isFunction(InputProxy); assert.doesNotThrow(() => { new InputProxy(); }); assert.instanceOf(new InputProxy(), InputProxy); }); test('should inherit from Rx.Observable', () => { assert.instanceOf(new InputProxy(), Rx.Observable); }); test('should has pass, get and dispose methods', () => { let proxy = new InputProxy(); assert.isFunction(proxy.pass); assert.isFunction(proxy.get); assert.isFunction(proxy.dispose); }); }); suite('pass method', () => { let proxy; setup(() => { proxy = new InputProxy(); }); teardown(() => { proxy.dispose(); proxy = null; }); test('should not throw if passed object is Observable', () => { assert.doesNotThrow(() => { proxy.pass(Rx.Observable.just(3)); }); }); test('should throw if more that one Observable passed', () => { assert.throws(() => { proxy.pass( Rx.Observable.just(3), Rx.Observable.just(4), Rx.Observable.just(5) ); }, /only one source can be passed/); }); test('should throw if pass method is called more than once', () => { proxy.pass(Rx.Observable.just(3)); assert.throws(() => { proxy.pass(Rx.Observable.just(4)); }, /source already passed/); }); test('should throw if passed value is not Observable', () => { assert.throws(() => { proxy.pass(); }, /observable/); assert.throws(() => { proxy.pass(undefined); }, /observable/); assert.throws(() => { proxy.pass({ }); }, /observable/); assert.throws(() => { proxy.pass(() => { }); }, /observable/); assert.throws(() => { proxy.pass({ subscribe: () => { } }); }, /observable/); }); suite('passing values', () => { test('should yield values from passed streams', (done) => { let value = { }; proxy.pass( Rx.Observable.just(value).delay(1) ); proxy.subscribe((x) => { assert.strictEqual(x, value); done(); }); }); test('should not pass values after `dispose` is called', (done) => { proxy.pass( Rx.Observable.interval(100) .map((x) => x + 1) .take(3) ); proxy.subscribe((x) => { assert.notStrictEqual(x, 3); }); setTimeout(() => { proxy.dispose(); }, 250); setTimeout(() => { done(); }, 400); }); }); });