-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Provide timestamp as argument to rAF callbacks when running Jest tests #35919
Conversation
Thanks for this - completely agree with adding this argument, but IIRC the value should be provided by |
Base commit: a69a924 |
Thanks for checking this @robhogan. Your suggestion makes sense. I was only testing it with modern timers where performance.now is mocked. Will update the PR after the weekend |
@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
facebook#35919) Summary: This change aligns requestAnimationFrame implementation used in Jest environment with web standard, and with the implementation that runs in the application environment. As per specification https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame#parameters – requestAnimationFrame callback gets a single parameter, which represents the current frame timestamp. The current polyfill maps requestAnimationFrame directly to setTimeout which makes the callback execute without any parameters. ## Changelog [General] [Fixed] - Jest mocked requestAnimationFrame callbacks now receive a timestamp parameter Pull Request resolved: facebook#35919 Test Plan: 1. execute jest test suite to make sure nothing breaks 2. add the below code to one of the tests: ``` jest.useFakeTimers(); requestAnimationFrame((timestamp) => console.log("rAF", timestamp)); jest.runOnlyPendingTimers(); jest.useRealTimers(); ``` this code will print `undefined` before and numer `0` representing the mocked frame time after this change. Reviewed By: jacdebug Differential Revision: D42676544 Pulled By: robhogan fbshipit-source-id: 363dc506ccc4bd034408fbb35ad3151875a8d309
Summary
This change aligns requestAnimationFrame implementation used in Jest environment with web standard, and with the implementation that runs in the application environment.
As per specification https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame#parameters – requestAnimationFrame callback gets a single parameter, which represents the current frame timestamp. The current polyfill maps requestAnimationFrame directly to setTimeout which makes the callback execute without any parameters.
Changelog
[General] [Fixed] - Jest mocked requestAnimationFrame callbacks now receive a timestamp parameter
Test Plan
this code will print
undefined
before and numer0
representing the mocked frame time after this change.