1

我正在尝试在我的代码上构建一些测试,但我无法运行它,因为它无法识别导入语句。

当我运行“npm test”来检查我的测试时,我收到了这个错误:

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from 'react'
                                                                                         ^^^^^^

SyntaxError: Unexpected token import

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-cli/node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at <anonymous>

这些是我的.babelrcpackage.json文件:

包.json:

{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"dev": "^0.1.3",
"react": "^15.6.1",
"react-google-button": "^0.3.0",
"react-google-login": "^2.9.2",
"react-google-login-component": "^0.7.0",
"react-native-google-signin": "^0.10.0",
"react-redirect": "^1.0.0",
"react-router-dom": "^4.1.2",
"react-scripts": "0.9.5"
 },

"devDependencies": {
"babel-jest": "^20.0.3",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"enzyme": "^2.9.1",
"enzyme-to-json": "^1.5.1",
"identity-obj-proxy": "^3.0.0",
"jest-cli": "^20.0.4",
"react-addons-test-utils": "^15.6.0",
"react-dom": "^15.6.1"
 },

  "jest": {
"transform": {}
 },

"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"eject": "react-scripts eject"
 }
}

.babelrc:

{
  "plugins":["transform-react-jsx"],
  "presets": ["es2015", "react"],
  "env": {
    "test": {
      "plugins": ["transform-es215-modules-commonjs"]
    } 
  }
}
4

0 回答 0