-
Notifications
You must be signed in to change notification settings - Fork 26.1k
feat(zone.js): add jest fakeTimers support #39016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
jest
fakeTimers APIs' integration withfakeAsync()
.After enable this feature, calling
jest.useFakeTimers()
will make all testrun into
fakeAsync()
automatically.Also there are mappings between
jest
andzone
APIs.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()