【发布时间】:2019-10-23 05:24:43
【问题描述】:
在 Angular 文档中,我看到了这两个函数,tick() 和 flush()。这两个似乎都做类似的事情。从角度文档中,它说:
模拟 fakeAsync 区域中计时器的异步时间流逝。
对于冲洗:
通过排空宏任务队列直到它为空,模拟 fakeAsync 区域中的计时器的异步时间流逝。返回值是已经过去的毫秒数。
谁能给我解释一下区别?
编辑(在 cmets 中回答):
另外,angular documentation中tick()是不带参数使用的,该行的注释甚至使用了短语“flush”
it('should display error when TwainService fails', fakeAsync(() => {
// tell spy to return an error observable
getQuoteSpy.and.returnValue(
throwError('TwainService test failure'));
fixture.detectChanges(); // onInit()
// sync spy errors immediately after init
tick(); // flush the component's setTimeout()
fixture.detectChanges(); // update errorMessage within setTimeout()
expect(errorMessage()).toMatch(/test failure/, 'should display error');
expect(quoteEl.textContent).toBe('...', 'should show placeholder');
}));
【问题讨论】:
标签: angular typescript testing ionic-framework jasmine