feat(zone.js): add jest fakeTimers support#39016
feat(zone.js): add jest fakeTimers support#39016JiaLiPassion wants to merge 1 commit intoangular:masterfrom
Conversation
4be1bee to
8347cd5
Compare
Close angular#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()`
8347cd5 to
b6a79b5
Compare
|
I like this 👍
|
|
@ahnpnl , thanks, and this feature will not affect current zone.js integration with jest. So we can keep the backward compatibility for jest version And since I am planning to add a new doc for |
IgorMinar
left a comment
There was a problem hiding this comment.
lgtm, but I have to admit that I don't have the domain knowledge to thoroughly review some parts of this PR.
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Close #38851, support
jestfakeTimers APIs' integration withfakeAsync().After enable this feature, calling
jest.useFakeTimers()will make all testrun into
fakeAsync()automatically.Also there are mappings between
jestandzoneAPIs.jest.runAllTicks()will callflushMicrotasks().jest.runAllTimers()will callflush().jest.advanceTimersByTime()will calltick()jest.runOnlyPendingTimers()will callflushOnlyPendingTimers()jest.advanceTimersToNextTimer()will calltickToNext()jest.clearAllTimers()will callremoveAllTimers()jest.getTimerCount()will callgetTimerCount()