且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

@ ngrx/effects:测试一个效果会返回empty()

更新时间:2023-11-17 16:22:58

问题是您正在将实际结果与cold('|')进行比较.

The problem is that you are comparing the actual result against cold('|').

cold('|')中的竖线字符表示可观察流的完成.但是,您的效果将无法完成. empty()可观察对象确实完成了,但是从switchMap返回empty()只是看到该可观察对象已合并到效果可观察对象的流中-它无法完成效果可观察对象.

The pipe character in cold('|') represents the completion of the observable stream. However, your effect will not complete. The empty() observable does complete, but returning empty() from switchMap just sees that observable merged into the effect observable's stream - it does not complete the effect observable.

相反,您应该将实际结果与cold('')进行比较-这是一个不发出任何值且未完成的可观察对象.

Instead, you should compare the actual result against cold('') - an observable that emits no values and does not complete.