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
|
2022-08-05 10:50:37 +00:00
|
|
|
import * as smartrx from '../ts/index.js';
|
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();
|
2022-01-24 02:44:13 +00:00
|
|
|
expect(testObservablemap).toBeInstanceOf(smartrx.Observablemap);
|
2018-10-10 14:44:44 +00:00
|
|
|
});
|
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();
|
2022-08-05 10:50:37 +00:00
|
|
|
testObservable1 = testObservablemap.getSubjectForEmitterEvent(testEmitter, 'event1');
|
2020-07-12 01:53:32 +00:00
|
|
|
testObservable1.subscribe((x) => {
|
2018-10-10 14:44:44 +00:00
|
|
|
done.resolve();
|
|
|
|
});
|
2022-08-05 10:50:37 +00:00
|
|
|
testObservable2 = testObservablemap.getSubjectForEmitterEvent(testEmitter, 'event1');
|
|
|
|
testObservable3 = testObservablemap.getSubjectForEmitterEvent(testEmitter, 'event2');
|
2022-01-24 02:44:13 +00:00
|
|
|
expect(testObservable1 === testObservable2).toBeTrue();
|
|
|
|
expect(testObservable1 === testObservable3).toBeFalse();
|
2018-10-10 14:44:44 +00:00
|
|
|
testEmitter.emit('event1');
|
|
|
|
await done.promise;
|
|
|
|
});
|
2017-10-26 20:56:01 +00:00
|
|
|
|
2018-10-10 14:44:44 +00:00
|
|
|
tap.start();
|