safe-combine-latest.observable.spec.ts 1.44 KiB
import { Observable } from 'rxjs';
import { MarbleTestScheduler } from '../testing/marbles';
import { safeCombineLatest } from './safe-combine-latest.observable';
describe('safe-combine-latest', () => {
  let scheduler: MarbleTestScheduler<any>;
  const VALUES: { [key: string]: number | number[] } = {
    a: 0,
    b: 1,
    c: 2,
    d: 3,
    e: 4,
    N: [],
    A: [0],
    B: [1],
    C: [2],
    U: [1, 3, 4],
    V: [2, 3, 4],
  beforeEach(() => {
    scheduler = MarbleTestScheduler.create(VALUES);
  });
  it('should emit an empty array on empty inputs', () =>
    scheduler.run(({ cold, expectObservable }) => {
      const inputs$: Array<Observable<number>> = [
        // EMPTY
      const output = 'N';
      expectObservable(safeCombineLatest(inputs$)).toBe(output);
    }));
  it('should emit an 1-sized array on 1-sized input', () =>
    scheduler.run(({ cold, expectObservable }) => {
      const inputs$: Array<Observable<number>> = [
        cold('abc'),
      const output = 'ABC';
      expectObservable(safeCombineLatest(inputs$)).toBe(output);
    }));
  it('should emit combinations of each inputs', () =>
    scheduler.run(({ cold, expectObservable }) => {
      const inputs$: Array<Observable<number>> = [
        cold('a-b-c'),
        cold('d'),
        cold('--e'),
      const output = '--U-V';
      expectObservable(safeCombineLatest(inputs$)).toBe(output);
    }));
});