2017-10-26 20:56:01 +00:00
|
|
|
// import test framework
|
2018-10-10 14:44:44 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
|
|
|
import * as events from 'events';
|
|
|
|
import * as rx from 'rxjs';
|
|
|
|
import * as smartpromise from '@pushrocks/smartpromise';
|
2017-10-26 20:56:01 +00:00
|
|
|
|
|
|
|
// import the module
|
2018-10-10 14:44:44 +00:00
|
|
|
import * as smartrx from '../ts/index';
|
2017-10-26 20:56:01 +00:00
|
|
|
|
2018-10-10 14:44:44 +00:00
|
|
|
let testObservablemap: smartrx.Observablemap;
|
|
|
|
let testObservable1: rx.Observable<any>;
|
|
|
|
let testObservable2: rx.Observable<any>;
|
|
|
|
let testObservable3: rx.Observable<any>;
|
|
|
|
let testEmitter: events.EventEmitter;
|
2017-10-26 20:56:01 +00:00
|
|
|
|
|
|
|
tap.test('should create an instance', async () => {
|
2018-10-10 14:44:44 +00:00
|
|
|
testObservablemap = new smartrx.Observablemap();
|
|
|
|
expect(testObservablemap).be.instanceof(smartrx.Observablemap);
|
|
|
|
});
|
2017-10-26 20:56:01 +00:00
|
|
|
|
|
|
|
tap.test('should accept a new emitter', async () => {
|
2018-10-10 14:44:44 +00:00
|
|
|
let done = smartpromise.defer();
|
|
|
|
testEmitter = new events.EventEmitter();
|
|
|
|
testObservable1 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1');
|
2017-10-26 20:56:01 +00:00
|
|
|
testObservable1.subscribe(x => {
|
2018-10-10 14:44:44 +00:00
|
|
|
done.resolve();
|
|
|
|
});
|
|
|
|
testObservable2 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1');
|
|
|
|
testObservable3 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event2');
|
|
|
|
expect(testObservable1 === testObservable2).to.be.true;
|
|
|
|
expect(testObservable1 === testObservable3).to.be.false;
|
|
|
|
testEmitter.emit('event1');
|
|
|
|
await done.promise;
|
|
|
|
});
|
2017-10-26 20:56:01 +00:00
|
|
|
|
2018-10-10 14:44:44 +00:00
|
|
|
tap.start();
|