当我运行Jest单元测试时,升级到React后出现此错误:
React depends on requestAnimationFrame. Make sure that you load a polyfill in older browsers.
我如何解决它?
我正在使用Jest 18.1.0。
找到了解决方法!
脚步:
__mocks__/react.js
const react = require('react'); // Resolution for requestAnimationFrame not supported in jest error : // https://github.com/facebook/react/issues/9102#issuecomment-283873039 global.window = global; window.addEventListener = () => {}; window.requestAnimationFrame = () => { throw new Error('requestAnimationFrame is not supported in Node'); }; module.exports = react;
如标记在代码上的注释
这是来自https://github.com/facebook/react/issues/9102#issuecomment-283873039的解决方案