我的快照测试因 react native 而失败。我遵循了一些解决方案,但没有任何效果。 我面临的错误是:
/Users/USER_NAME/Projects/project_name/node_modules/react-native-animated-ellipsis/dist/AnimatedEllipsis.js:1 (function (exports, require, module, __filename, __dirname) { import React, { Component } from 'react'; ^^^^^^ 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"
]
}
}
}
最佳答案
我不确定为什么你想对你的项目依赖项之一应用 babel 转换,但按照错误消息,即使你想对react-native-animated-ellipsis 应用 babel 转换,你可能应该在 src 上执行此操作并排除 dist 文件夹。
关于reactjs - 语法错误: Unexpected token import with Jest + react-native-animated-ellipsis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49691099/