我在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$);
});
现在我正在接收
问题:
请注意,我使用的是Angular 10.x.y,NGRX 10.x.y,NX 10.x.y和Spectator 5.x.y。