在lettable operator之前,我做了一个帮助来修改debounceTime方法,所以它使用了一个TestScheduler:
export function mockDebounceTime(
scheduler: TestScheduler,
overrideTime: number,
): void {
const originalDebounce = Observable.prototype.debounceTime;
spyOn(Observable.prototype, 'debounceTime').and.callFake(function(
time: number,
): void {
return originalDebounce.call(
this,
overrideTime,
scheduler,
);
});
}
Run Code Online (Sandbox Code Playgroud)
因此,以下Observable的测试很简单:
@Effect()
public filterUpdated$ = this.actions$
.ofType(UPDATE_FILTERS)
.debounceTime(DEFAULT_DEBOUNCE_TIME)
.mergeMap(action => [...])
Run Code Online (Sandbox Code Playgroud)
对于lettable运算符,filterUpdated $ Observable的编写方式如下:
@Effect()
public filterUpdated$ = this.actions$
.ofType(UPDATE_FILTERS)
.pipe(
debounceTime(DEFAULT_DEBOUNCE_TIME),
mergeMap(action => [...])
);
Run Code Online (Sandbox Code Playgroud)
我不能修复debounceTime运算符了!如何将testScheduler传递给debounceTime运算符?