我们正在尝试将我们的测试环境从 jest 26 升级到 27。这是我们的工作分支:https://github.com/pass-culture/pass-culture-app-native/tree/update-jest-27
到目前为止,我们遇到了一堆我们仍然无法修复的错误,例如:
TypeError: requestAnimationFrame 不是函数
TypeError: requestAnimationFrame is not a function
at start (node_modules/react-native/Libraries/Animated/animations/TimingAnimation.js:133:34)
TypeError: global.cancelAnimationFrame 不是函数
TypeError: global.cancelAnimationFrame is not a function
at TimingAnimation.stop (node_modules/react-native/Libraries/Animated/animations/TimingAnimation.js:176:12)
Hook 超时超过 5000 毫秒
thrown: "Exceeded timeout of 5000 ms for a hook.
Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
我们有很多测试都失败了,并且找到了一堆建议,但没有一个解决我们的测试
这是最常见的错误。
如果你有什么想法,要取得进展,欢迎。
复制
- 克隆我的 repo
git clone --single-branch --branche update-jest-27 https://github.com/pass-culture/pass-culture-app-native.git
cd pass-culture-app-native
yarn
yarn 测试:单元
附加上下文
System:
OS: Linux dka 5.8.0-0.bpo.2-amd64 #1 SMP Debian 5.8.10-1~bpo10+1 (2020-09-26) x86_64 GNU/Linux
CPU: (8) arm64
Binaries:
Node: v16.13.2 - /home/dka/.nvm/versions/node/v16.13.2/bin/node
Yarn: 1.22.15 - /home/dka/.yarn/bin/yarn
npmPackages:
jest: 26.0.14 => 27.5.2
react-native: 0.68.2
最佳答案
尝试添加到 jestSetup 文件中
beforeEach(() => {
// @ts-ignore
global.requestAnimationFrame = function (callback: any) {
setTimeout(callback, 0);
};
global.cancelAnimationFrame = function (callback: any) {
setTimeout(callback, 0);
};
});
关于javascript - React Native jest 26 到 jest 27 升级很痛苦,超时和动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73137934/