【发布时间】:2021-04-16 15:53:56
【问题描述】:
我有一个 NGRX 效果 - 根据状态 - 发出延迟的动作或什么也不发出。 我想写一个测试,涵盖这两种情况。
这是效果:
myEffect$ = createEffect(() =>
this.actions$.pipe(
ofType(MyAction),
filter(state => state.foo === false),
delay(4000),
map(state => myOtherAction())
)
);
对于它应该发出有延迟的 otherAction 的情况的测试工作正常:
describe('emit my action', () => {
const action = MyAction();
it('should return a stream with myOtherAction', () => {
const scheduler = getTestScheduler();
scheduler.run(helpers => {
// build the observable with the action
actions = hot('-a', { a: action });
// define what is the expected outcome of the effect
const expected = {
b: MyOtherAction()
};
helpers.expectObservable(effects.myEffect$).toBe('- 4000ms b', expected);
});
});
});
但我不知道如何测试另一个状态,它应该不发出另一个动作(流的长度为零):
it('should return an empty stream', () => {
store.setState({
myFeature: {
foo: true
}
});
// ???
});
请帮忙:)
【问题讨论】:
标签: jasmine ngrx-effects jasmine-marbles rxjs-marbles ngrx-test