如何对这个 Observable 进行单元测试?
e1.pipe(
concatMap(x => of(x).pipe(withLatestFrom(e2)))
);
以下单元测试失败:
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);
});
为了通过这个单元测试,应该如何编写弹珠?我做错了什么?我希望通过concatMap
在链中(之前withLatestFrom
)插入运算符,我还必须以某种方式在弹珠中“标记”它。