填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

tick

為 fakeAsync Zone 中的計時器模擬非同步時間流逝。

Simulates the asynchronous passage of time for the timers in the fakeAsync zone.

檢視"說明"...

tick(millis: number = 0, tickOptions: { processNewMacroTasksSynchronously: boolean; } = { processNewMacroTasksSynchronously: true }): void
      
      tick(millis: number = 0, tickOptions: { processNewMacroTasksSynchronously: boolean; } = {
    processNewMacroTasksSynchronously: true
}): void
    
引數
millis number
可選. 預設值是 `0`.
tickOptions object
可選. 預設值是 `{ processNewMacroTasksSynchronously: true }`.
返回值

void

說明

在此函式開始時以及執行任何計時器回呼(Callback)之後,微任務佇列就會耗盡。

The microtasks queue is drained at the very start of this function and after any timer callback has been executed.

使用說明

例子

Example

describe('this test', () => { it('looks async but is synchronous', <any>fakeAsync((): void => { let flag = false; setTimeout(() => { flag = true; }, 100); expect(flag).toBe(false); tick(50); expect(flag).toBe(false); tick(50); expect(flag).toBe(true); })); });
      
      describe('this test', () => {
  it('looks async but is synchronous', <any>fakeAsync((): void => {
       let flag = false;
       setTimeout(() => {
         flag = true;
       }, 100);
       expect(flag).toBe(false);
       tick(50);
       expect(flag).toBe(false);
       tick(50);
       expect(flag).toBe(true);
     }));
});