React native Jest:测试套件无法运行(Expo SDK需要Expo才能运行)
我的RN expo项目真的很难搞笑和运行(所以我可以到处玩并学习它) B.法律改革委员会React native Jest:测试套件无法运行(Expo SDK需要Expo才能运行),react-native,jestjs,expo,babel-jest,React Native,Jestjs,Expo,Babel Jest,我的RN expo项目真的很难搞笑和运行(所以我可以到处玩并学习它) B.法律改革委员会 我认为您的错误在package.json文件中的jest键中,您的Babel配置预设也错误 首先将“^32.0.0”添加到您的devdependency(因为您使用的是SDK 32),然后必须将包.json中的jest密钥更改为: “开玩笑”:{ “预设”:“玩笑博览会”, } 将.babelrc预设键更改为:预设:['babel-preset-expo']。或者删除它并创建一个包含以下内容的babel.
我认为您的错误在
package.json
文件中的jest
键中,您的Babel配置预设也错误
首先将“^32.0.0”添加到您的devdependency
(因为您使用的是SDK 32),然后必须将包.json中的jest密钥更改为:
“开玩笑”:{
“预设”:“玩笑博览会”,
}
将.babelrc
预设键更改为:预设:['babel-preset-expo']
。或者删除它并创建一个包含以下内容的babel.config.js
文件(推荐):
module.exports=api=>{
api.cache(true);
返回{
预设:['babel-preset-expo'],
};
};
如果这仍然不起作用,请检查项目,它应该为您指出正确的方向。或者留下评论,我会编辑答案以帮助您。当我查看您链接到的项目时,我在包中没有看到任何笑话。json
?@norfeldt抱歉,显然我忘了向该分支推送一些代码,但您必须将jest expo
添加到devdependences
并遵循我告诉您的配置。我将更新我的答案以包含此内容。@norfeldt更改了指向另一个项目的链接,该项目应该对您更有帮助。卸载.babelrc
并安装jest expo
(再次)并将jest预设更改为jest expo
,成功了。非常感谢。现在它只是在大喊大叫App test.js
(必须是在expo init
期间创建的)说SyntaxError:Unexpected identifier
{import React from'React';
。这似乎永远不会结束。您还可以从devDependencies
中删除jest
,因为jest expo
包含了自己的jest
dist。
FAIL screens/HomeScreen.test.js
● Test suite failed to run
The Expo SDK requires Expo to run. It appears the native Expo modules are unavailable and this code is not running on Expo. Visit https://docs.expo.io to learn more about developing an Expo project.
at Object.<anonymous> (node_modules/expo/src/environment/validate.ts:11:9)
at Object.require (node_modules/expo/build/Expo.js:278:1)
FAIL __tests__/App-test.js
● Test suite failed to run
The Expo SDK requires Expo to run. It appears the native Expo modules are unavailable and this code is not running on Expo. Visit https://docs.expo.io to learn more about developing an Expo project.
at Object.<anonymous> (node_modules/expo/src/environment/validate.ts:11:9)
at Object.require (node_modules/expo/build/Expo.js:278:1)
PASS components/__tests__/StyledText-test.js (7.769s)
Test Suites: 2 failed, 1 passed, 3 total
Tests: 1 passed, 1 total
Snapshots: 1 passed, 1 total
Time: 10.477s
Ran all test suites.
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject",
"test": "jest --watchAll"
},
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|react-clone-referenced-element|expo(nent)?|@expo(nent)?/.*|react-navigation|sentry-expo))"
]
},
"dependencies": {
"@expo/samples": "2.1.1",
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-navigation": "^3.0.9"
},
"devDependencies": {
"babel-preset-expo": "^5.0.0",
"jest": "^24.7.1",
"react-test-renderer": "^16.8.6"
},
"private": true
}
{
"presets": ["react-native"]
}