问题描述
我在Effects
中有此代码:
@Injectable()
export class MyEffects {
readonly counter$ = createEffect(() =>
this.actions$.pipe(
ofType(someAction),withLatestFrom(this.store$.pipe(select(selectStatusFailed))),exhaustMap(([{ someObj },statusFailed]) => {
return interval(1000).pipe(
scan(acc => acc - 1,someObj.expirationTime),// expiration time is expressed in seconds
filter(counter => counter === 0),filter(() => !statusFailed),mapTo(anAction({ someObj })),takeUntil(
this.actions$.pipe(ofType(anAction,anotherAction)),),);
}),);
}
我想测试一下,但是由于我是大理石图以及大理石测试的新手,所以我遇到了几个问题。
到目前为止,我的尝试:
import { cold,hot } from '@nrwl/angular/testing';
test('something',() => {
const mock = myMock({ expirationTime: 5 });
const action = someAction({ mock });
const completion = anAction({ mock });
actions$ = hot('-a',{ a: action });
const expected$ = cold(
'b 1000ms c 1000ms d 1000ms e 1000ms f 1000ms (g|)',{
b: 4,c: 3,d: 2,e: 1,f: 0,g: completion,},);
expect(myEffects.counter$).toBeObservable(expected$);
});
现在我正在接收
- 预期-95
- 已接收+ 1
- 数组[]
问题:
- 如何在分派两个动作中的任何一个时测试发射的值以及如何检查发射的值是否停止?
- 有什么方法可以更轻松地对其进行调试?目前,我很难找到问题所在。
请注意,我使用的是Angular 10.x.y,NGRX 10.x.y,NX 10.x.y和Spectator 5.x.y。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)