samedi 22 août 2020

RxJs Marble testing concatMap with withLatestFrom

How can be unit tested this Observable?

e1.pipe(
    concatMap(x => of(x).pipe(withLatestFrom(e2)))
);

Following unit test fails:

        it('test', () => {
            const e1 = hot(       '--1^---2----3-|');
            const e2 = hot(       '-a-^-b-----c--|');
            const expected = cold(   '----x----y-|', {
                x: ['2', 'b'],
                y: ['3', 'c']
            });

            const result = e1.pipe(
                concatMap(x => of(x).pipe(
                    withLatestFrom(e2))
                )
            );

            // but this works:
            // const result = e1.pipe(withLatestFrom(e2));

            expect(result).toBeObservable(expected);
        });

How the marbles should be written in order to pass this unit test? What did I do wrong? I expect by inserting concatMap operator in the chain (before withLatestFrom) I have to also somehow "mark" it in the marbles.

Aucun commentaire:

Enregistrer un commentaire