diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index 70f89466a438..86689f71e2a7 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -68,7 +68,7 @@ export interface Jest { */ advanceTimersByTimeAsync(msToRun: number): Promise; /** - * Advances all timers by the needed milliseconds to execute currently scheduled animation frames. + * Advances all timers by the needed milliseconds to execute callbacks current scheduled with `requestAnimationFrame`. * `advanceTimersToNextFrame()` helpful way to execute code that is scheduled using `requestAnimationFrame`. * * @remarks diff --git a/packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts b/packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts index 944bc2f586be..a57bac0fd7e9 100644 --- a/packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts +++ b/packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts @@ -768,6 +768,29 @@ describe('FakeTimers', () => { timers.advanceTimersByTime(1); expect(runOrder).toEqual(['frame', 'timeout']); }); + + it('should call animation frame callbacks with the latest system time', () => { + const global = { + Date, + clearTimeout, + performance, + process, + requestAnimationFrame: () => -1, + setTimeout, + } as unknown as typeof globalThis; + + const timers = new FakeTimers({config: makeProjectConfig(), global}); + timers.useFakeTimers(); + + const callback = jest.fn(); + + global.requestAnimationFrame(callback); + + timers.advanceTimersToNextFrame(); + + // `requestAnimationFrame` callbacks are called with a `DOMHighResTimeStamp` + expect(callback).toHaveBeenCalledWith(global.performance.now()); + }); }); describe('reset', () => {