我有一个返回的效果EMPTY
在一种情况下可以观察到。我正在尝试测试这个案例,但我似乎不知道如何测试EMPTY
可观察到的?
我的代码如下:
效果:
effect$ = createEffect(() =>
this.actions$.pipe(
ofType(someAction),
mergeMap(([action]) => {
if (someCondition) {
return EMPTY <-- this is what I am trying to test
}
return someServiceCall.pipe(
map((offers) => //dispatch some action,
catchError((error: string) => // dispatch another action),
)
}),
),
)
这是我的单元测试尝试,但失败了
Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
.
考虑到测试中已经满足条件:
it('should return EMPTY when ...', (done) => {
actions$ = of(someAction)
effects.effect$.subscribe((res) => {
expect(res).toEqual(never)
done()
})
})
如果回报是的话我可以让它工作of(null)
代替EMPTY
。但我真的很想知道如何测试这个案例。
看来我们在 RxJs 中有一个特定的操作来检查可观察量是否为空。操作是isEmpty()
it('should return EMPTY when ...', (done) => {
actions$ = of(someAction)
effects.effect$.pipe(isEmpty()).subscribe( (res) => {
expect(res).toEqual(true)
done()
});
仅当 observable 确实返回空时 res 才会为 true
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)