给出两个NGRX效果(使用nrwl / nx dataPersistence表示法),其中第二个通过takeUntil
绑定到第一个:
@Injectable()
export class ModuleEffects {
@Effect() effectOne$ = this.dataPersistence.fetch(ModuleActionTypes.ActionOne, {
run: (action: ActionOne, state: ModulePartialState) => {
return new SomeReturnAction();
},
});
@Effect() effectTwo$ = this.dataPersistence.fetch(ModuleActionTypes.ActionTwo, {
run: (action: ActionTwo, state: ModulePartialState) => {
return this.service.apiCall().pipe(
takeUntil(this.effectOne$),
map(result => new SomeResultAction(result))
);
},
});
目的是在effectOne $发出后立即停止通过UI输入发出SomeResultAction(效果很好)。
我现在正尝试使用茉莉花大理石lib测试这些效果:
it('should stop emitting after effectOne$ has emitted', () => {
const action = new ActionTwo();
const interruptingAction = new ActionOne();
const outcome = new SomeResultAction(mockedResult);
actions = hot(' -a--a-ia|', { a: action, i: interruptingAction });
const expected = cold('-b--b--b|', { b: outcome });
expect(effects.effectTwo$).toBeObservable(expected);
});
即使我希望expected
被派发后,interruptingAction
的观察结果也会完成,该测试也会成功。