小编Gui*_*ury的帖子

在RxJS 5.5中测试和模拟可调运算符

在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运算符?

typescript rxjs5 ngrx-effects

9
推荐指数
1
解决办法
3244
查看次数

标签 统计

ngrx-effects ×1

rxjs5 ×1

typescript ×1