![](/img/trans.png)
[英]SyntaxError - node_modules/react-native/Libraries/polyfills/error-guard.js: Missing semicolon. (14:4) on running jest in react native library
[英]Error in node_modules/react-native/Libraries/Modal/Modal.js while testing with Jest
home.test.js
import React from 'react';
import Home from './index';
import renderer from 'react-test-renderer';
it('renders home', ()=> {
const view = renderer.create(
<Home></Home>
).toJSON();
expect(view).toMatchSnapshot();
});
不幸的是,我不知道这是什么问题。 我认为测试写得很好。
任何帮助都会很棒。
我如何解决该错误使测试无法运行的问题
遇到此错误,导致我的测试无法运行
 错误页面
经过数小时的无奈之后,我两次删除了node_modules文件夹,并通过Stackoverflow和Google重新安装并搜寻了它,但没有任何解决方案,于是,我决定创建一个新的CRNA项目,看看它是否也会遇到同样的问题。 当我看到新存储库中不存在问题时,我使用以下步骤使其正常工作:
```{
"devDependencies": {
"react-native-scripts": "1.5.0",
"jest-expo": "^21.0.2",
"react-test-renderer": "16.0.0-alpha.12"
},
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!react-native|expo|react-navigation|native-base-shoutem-theme|@shoutem/theme|@shoutem/animation|@shoutem/ui|tcomb-form-native)"
]
},
"dependencies": {
"react-native": “0.48.4”,
"expo": "^21.0.2",
"react": "16.0.0-alpha.12"
},
3. The core difference was in upgrading react-native from 0.48.0 to 0.48.4; react-native-scripts from 1.2.1 to 1.5.0 and including the transformIgnorePatterns under the jest option. NOTE: The portion from *native-base* in the transformIgnorePatterns was included because I used NativeBase in the project. 4. I then added a .babelrc with the following details:
{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
}
}
```5.现在运行测试给我结果:
ing 通过测试所有测试均为绿色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.