react-native/jest
Krzysztof Magiera b44fe4deee Provide timestamp as argument to rAF callbacks when running Jest tests (#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: https://github.com/facebook/react-native/pull/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
2023-01-23 09:53:01 -08:00
..
private Remove babel plugins from jest preprocessor which are part of preset 2022-05-12 03:48:24 -07:00
assetFileTransformer.js fix(jest): make assetFileTransformer return an object (#33756) 2022-06-17 10:27:47 -07:00
local-setup.js Fail tests on console.error() or console.warn() 2022-12-01 06:59:04 -08:00
mockComponent.js Support ES modules in mockComponent 2022-12-28 12:35:03 -08:00
mockModal.js fix(jest/setup): fix circular dependencies in mockModal (#32964) 2022-01-26 23:54:55 -08:00
mockNativeComponent.js ESM requireNativeComponent 2023-01-03 18:09:06 -08:00
MockNativeMethods.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
mockScrollView.js ESM requireNativeComponent 2023-01-03 18:09:06 -08:00
react-native-env.js fix(jest-env): pass exportConditions (#35203) 2022-11-10 06:21:53 -08:00
renderer.js @emails -> @oncall (remaining ones) 2022-09-15 15:54:10 -07:00
setup.js Provide timestamp as argument to rAF callbacks when running Jest tests (#35919) 2023-01-23 09:53:01 -08:00