angular-docs-cn/packages/zone.js/test/jest
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
..
jest-zone-patch-fake-timer.js feat(zone.js): add jest fakeTimers support (#39016) 2020-10-05 13:23:17 -07:00
jest-zone.js feat(zone.js): add jest fakeTimers support (#39016) 2020-10-05 13:23:17 -07:00
jest.config.js feat(zone.js): add jest fakeTimers support (#39016) 2020-10-05 13:23:17 -07:00
jest.node.config.js feat(zone.js): add jest fakeTimers support (#39016) 2020-10-05 13:23:17 -07:00
jest.spec.js feat(zone.js): add jest fakeTimers support (#39016) 2020-10-05 13:23:17 -07:00
zone-jsdom-environment.js feat(zone.js): add jest fakeTimers support (#39016) 2020-10-05 13:23:17 -07:00
zone-node-environment.js feat(zone.js): add jest fakeTimers support (#39016) 2020-10-05 13:23:17 -07:00