3088096684
Summary: `Jest` allows to use fake timers and according to https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame the return value should be `A long integer value, the request id, that uniquely identifies the entry in the callback list`. This allows to use `cancelAnimationFrame`. In current implementation of `jest/setup.js`, the return value is undefined. Therefore it's not possible to cancel the animation frame request. ``` let id = null; const registerCallback = (callback) => { clearCallback(); id = requestAnimationFrame(() => { id = null; callback(); }); }; const clearCallback = () => { if (null !== id) { cancelAnimationFrame(id); id = null; } }; ``` ``` jest.useFakeTimers(); const callback = jest.fn(); registerCallback(callback); clearCallback(); jest.runAllTimers(); expect(callback).toHaveBeenCalledTimes(0); // Will be error in current implementation, since nothing is cleared. And test will pass, after MR is merged ``` This is fake example, but the real usage is when the animation frame request should be removed on `ComponentWillUnmount`. [JEST] [BUGFIX] [requestAnimationFrame] - return request id Closes https://github.com/facebook/react-native/pull/16367 Differential Revision: D6060578 Pulled By: ericnakagawa fbshipit-source-id: c785a3380f5e267b48ae16fcf34dbbf95fa54178 |
||
---|---|---|
.. | ||
.eslintrc | ||
assetFileTransformer.js | ||
mockComponent.js | ||
preprocessor.js | ||
setup.js |