Logo
Explore Help
Sign In
honeymoose/angular-cn
1
0
Fork 0
You've already forked angular-cn
Code Issues Pull Requests Packages Projects Releases Wiki Activity
angular-cn/packages/zone.js/test/jest/jest-zone-patch-fake-timer.js

7 lines
232 B
JavaScript
Raw Normal View History

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-09-22 22:52:20 +09:00
const exportFakeTimersToSandboxGlobal = function(jestEnv) {
jestEnv.global.legacyFakeTimers = jestEnv.fakeTimers;
jestEnv.global.modernFakeTimers = jestEnv.fakeTimersModern;
};
module.exports = exportFakeTimersToSandboxGlobal;
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.1 Page: 515ms Template: 3ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API