Sac*_*nan 9 testing reactjs jestjs react-native
我想在我的 react-native 项目中使用 jest。我是玩笑和本机反应的新手。目前低于错误
Details:
/Users/sachigrannan/SKO/Alpha4-1/node_modules/react-native-iphone-x-helper/index.js:1
import { Dimensions, Platform, StatusBar } from 'react-native';
^
SyntaxError: Unexpected token {
at Runtime._execModule (node_modules/jest-runtime/build/index.js:1157:58)
at Object.<anonymous> (node_modules/react-navigation-stack/lib/commonjs/vendor/TransitionConfigs/CardStyleInterpolators.tsx:2:1)
Run Code Online (Sandbox Code Playgroud)
我已经在 package.json 中设置了这个。请帮忙!
"jest": {
"verbose": true,
"preset": "react-native",
"cacheDirectory": "./cache",
"coveragePathIgnorePatterns": [
"./app/utils/vendor"
],
"coverageThreshold": {
"global": {
"statements": 80
}
},
"transformIgnorePatterns": [
"node_modules/(?!(react-native|my-project|react-native-button|nodejs-mobile-react-native|react-navigation)/)"
]
}
Run Code Online (Sandbox Code Playgroud)
鉴于您的transformIgnorePatterns在引入库之前就已经工作,技巧只是将“react-native-iphone-x-helper”添加到“transformIgnorePatterns”属性中。
"node_modules/(?!(react-native|my-project|react-native-button|nodejs-mobile-react-native|react-navigation|react-native-iphone-x-helper)/)"
Run Code Online (Sandbox Code Playgroud)
也就是说,您最好删除“transformIgnorePatterns”并让"preset": "react-native"配置完成其工作。
我对预设遇到的唯一问题是当我在嵌套的 node_module 目录中有未转换的依赖项时,例如。
/path/to/myproject/node_modules/@react-navigation/bottom-tabs/node_modules/react-native-iphone-x-helper/index.js:1
import { Dimensions, Platform, StatusBar } from 'react-native';
^
Run Code Online (Sandbox Code Playgroud)
在这种情况下,问题是另一个模块使用了不同的版本,react-native-iphone-x-helper因此我必须更新该依赖项以使它们对齐。如果这不可行,你有纱线的分辨率字段
| 归档时间: |
|
| 查看次数: |
543 次 |
| 最近记录: |