由于语法错误,reactjs create_reate_app测试失败

时间:2018-07-25 21:09:16

标签: reactjs unit-testing

我的应用运行正常,但是运行测试时,出现以下错误:

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import Authentication from './authentication';

重点放在Authentication部分。似乎是我的测试无法以某种方式解释ES6并将其视为SyntaxError: Unexpected identifier

我做了一些研究,并由.babelrc更新,但这无济于事

在我的package.json中:

"scripts": {
"test": "react-scripts test --env=jsdom",
"build-css": "node-sass-chokidar src/ -o src/",
"watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
"start-js": "REACT_APP_ENV=local react-scripts start",
"start": "npm-run-all -p watch-css start-js",
"build-js": "react-scripts build",
"build": "npm-run-all build-css build-js",
"eject": "react-scripts eject"
},

和开发依赖

"devDependencies": {
"babel-eslint": "^7.2.3",
"browser-sync": "2.6.5",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^4.19.1",
"eslint-config-google": "^0.9.1",
"eslint-config-react-app": "^2.1.0",
"eslint-plugin-flowtype": "^2.46.2",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.7.0",
"gulp": "3.9.1",
"gulp-autoprefixer": "5.0.0",
"gulp-cache": "1.0.2",
"gulp-imagemin": "4.1.0",
"gulp-plumber": "1.1.0",
"gulp-rename": "1.2.2",
"gulp-rigger": "0.5.8",
"gulp-sass": "4.0.1",
"gulp-template": "5.0.0",
"gulp-uglify": "^3.0.0",
"react-test-renderer": "^16.4.1",
"uglify-js": "3.3.23"
}

然后是.babelrc

{
  "presets": ["es2015", "react"],
  "env": {
    "test": {
    "plugins": ["transform-export-extensions"],
    "only": [
      "./**/*.js",
      "node_modules/jest-runtime"
    ]
  }
}
}

0 个答案:

没有答案