我的快照测试因 react-native 失败。我遵循了一些解决方案,但没有任何效果。我面临的错误是:
/Users/USER_NAME/Projects/project_name/node_modules/react-native-animated-ellipsis/dist/AnimatedEllipsis.js:1(函数(导出,需要,模块,__filename,__dirname){导入反应,{组件}来自“反应” ; ^^^^^^ SyntaxError: Unexpected token import
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:178:20
在我的package.json
:
"jest": {
"preset": "react-native",
"transform": {
"^.+\\.js?$": "babel-jest"
},
"testPathIgnorePatterns": [
"/node_modules/",
"Tests/Setup.js"
],
"testMatch": [
"**/**/__tests__/**/*.js?(x)",
"**/?(*.)(spec|test).js?(x)"
],
"transformIgnorePatterns": [
"node_modules/(?!(react-native|rent-react-native|react-native-navigation|react-native-vector-icons|react-native-maps|react-native-animated-ellipsis)/)"
]
},
和.babelrc
{
"presets": ["react-native"],
"env": {
"test": {
"presets": ["env", "react-native"],
"plugins": ["react-native-animated-ellipsis"],
"only": [
"./**/*.js",
"node_modules/react-native-animated-ellipsis"
]
}
}
}