'RxJs - lossy zip marble testing

Following this post I've decided to write a marble test for this operator.

Here is a basic test:

  it('Test lossy zip', () => {

    const a = hot('a---a--------a-');
    const b = hot('--b----b---b---');

    const observable = zip(
      a.pipe(take(1)),
      b.pipe(take(1))
    ).pipe(
      mergeMapTo(from(['1'])),
      repeat()
    );
    const expected = cold('--1----1-----1-');
    expect(observable).toBeObservable(expected);
  });

This test passes as expected. However, when I decide to fire two emissions, like this, it fails:

const a = hot('a---a--------a-');
const b = hot('--b----b---b---');

const observable = zip(
  a.pipe(take(1)),
  b.pipe(take(1))
).pipe(
  mergeMapTo(from(['1', '2'])), //Here, emitting two items instead of one
  repeat()
);

I would expect the resulting observable to look like this:

const expected = cold('--(12)----(12)-----(12)-');

Or at least like this:

const expected = cold('--12---12----12-');

However both of them fail.

Is it a bug in jasmine-marbles or my expectations are wrong?



Solution 1:[1]

Apparently, according to the official documentation (which I haven't read thoroughly enough) parentheses as well as content of the group take up the relevant amount of frames:

'--(abc)-|': on frame 20, emit a, b, and c, then on frame 80 complete

And this means a working test for group emission would look like this:

  it('Should emit a grouped value', () => {

    const a = hot('a------a---------a---');
    const b = hot('--b-------b----b-----');

    const observable = zip(
      a.pipe(take(1)),
      b.pipe(take(1))
    ).pipe(
      mergeMapTo(from(['1', '2'])),
      repeat()
    );

    const expected = cold('--(12)----(12)---(12)');
    expect(observable).toBeObservable(expected);
  });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mikkel R. Lund