3

我的快照测试因 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"
      ]
    }
  }
}
4

1 回答 1

0

我不确定您为什么要对项目的一个依赖项应用 babel 转换,但遵循错误消息,即使您想在 react-native-animated-ellipsis 上应用 babel 转换,您也应该这样做src 并排除 dist 文件夹。

于 2018-04-06T12:36:14.883 回答