我正在尝试在Angular 4中测试setTimer函数。我的代码如下所示:
setTimer(timeCounter?: number, initialDelay?: number): Observable<number> {
return Observable.timer((isNumber(initialDelay) ? initialDelay * 1000 : DEFAULT_INITIAL_DELAY), DEFAULT_TIME_PERIOD)
.map(i => isNumber(timeCounter) ? timeCounter - i : DEFAULT_TIME_COUNTER - i)
.take(isNumber(timeCounter) ? timeCounter + 1 : DEFAULT_TIME_COUNTER + 1);
}
到目前为止,我已经尝试过:
it('should set timer and return time value', () => {
timerService.setTimer(15, 0).subscribe(value => {
expect(value).toEqual(jasmine.any(Number));
});
});
我希望我的测试更加一致,并使用jasmine.clock()。tick()检查值,如果可能的话......