【发布时间】:2019-05-18 00:15:08
【问题描述】:
我有一个方法可以将 observable 作为输入并切换到新的 observable。或者,我可以使用 map 而不是 switchMap。如何使用弹珠进行测试?
mapFirstToStr(ob: Observable<boolean>): Observable<string> {
return ob.pipe(
first(),
switchMap(val => of(val ? 'A' : 'B'))
);
}
这不起作用:
const source = cold('a', { a: true });
const expected = cold('b', { b: 'B' });
expect(mapFirstToStr(source)).toBeObservable(expected);
我收到以下错误:
期望值等于: [{"frame": 0, "notification": {"error": undefined, "hasValue": true, > "kind": "N", "value": "B"}}]
收到: [{"frame": 0, "notification": {"error": undefined, "hasValue": true, > "kind": "N", "value": "B"}}, {"frame": 0 , "notification": {"error": > undefined, "hasValue": false, "kind": "C", "value": undefined}}]
【问题讨论】:
标签: typescript observable rxjs-marbles