/* Copyright IBM Corp. 2017 */ import { concat, Observable, Observer } from 'rxjs'; import { distinct, map, tap, toArray } from 'rxjs/operators'; import { rxForkJoin } from '../src/utils/rx.utils'; describe('rx', () => { it('should forkjoin empty', () => { const rxDeps: Observable[] = []; let bInvoked = false; return rxForkJoin(rxDeps).pipe(map(res => { expect(res).toHaveLength(0); bInvoked = true; })) .toPromise() .then(() => expect(bInvoked).toBeTruthy()); }); it('should subscribe twice', () => { const rxSeq = Observable.create((o: Observer) => { o.next(Math.random()); o.complete(); }); const rxTotal = concat(rxSeq, rxSeq); return rxTotal.pipe( distinct(), toArray(), tap(arr => expect(arr.length).toBe(2))) .toPromise(); }); });