angular-docs-cn/packages/zone.js/lib/testing
JiaLiPassion 82d54fe8c3 feat(zone.js): add jest fakeTimers support (#39016)
Close #38851, support `jest` fakeTimers APIs' integration with `fakeAsync()`.
After enable this feature, calling `jest.useFakeTimers()` will make all test
run into `fakeAsync()` automatically.

```
beforeEach(() => {
    jest.useFakeTimers('modern');
  });
  afterEach(() => {
    jest.useRealTimers();
  });

  test('should run into fakeAsync() automatically', () => {
    const fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
    expect(fakeAsyncZoneSpec).toBeTruthy();
  });
```

Also there are mappings between `jest` and `zone` APIs.

- `jest.runAllTicks()` will call `flushMicrotasks()`.
- `jest.runAllTimers()` will call `flush()`.
- `jest.advanceTimersByTime()` will call `tick()`
- `jest.runOnlyPendingTimers()` will call `flushOnlyPendingTimers()`
- `jest.advanceTimersToNextTimer()` will call `tickToNext()`
- `jest.clearAllTimers()` will call `removeAllTimers()`
- `jest.getTimerCount()` will call `getTimerCount()`

PR Close #39016
2020-10-05 13:23:17 -07:00
..
async-testing.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
fake-async.ts feat(zone.js): add jest fakeTimers support (#39016) 2020-10-05 13:23:17 -07:00
promise-testing.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
zone-testing.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00