【发布时间】:2018-09-16 09:10:13
【问题描述】:
我的快照测试因 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:意外的令牌导入
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"
]
}
}
}
【问题讨论】:
-
我们也遇到了这个问题。通过
transformIgnorePatterns排除其他软件包似乎有效,但react-native-animated-ellipsis无效 -
解决了这个问题,只需从 repo 复制组件并将其直接放入我们的项目中。回购似乎很陈旧,我没有费心要求他们修复他们的
dist文件夹以兼容 es5。
标签: reactjs react-native react-redux jestjs react-animated