React Jest es6(休息传播运算符)babel配置不起作用

时间:2017-04-08 08:39:25

标签: reactjs jestjs babel-jest

我正在尝试使用react-tool-box创建应用。我也尝试使用Jest进行测试,

但是这个测试失败了。它看起来像Jest的es6配置问题。

●测试套件无法运行

/home/user/project/react-tool-box/react-toolbox-example/src/frontend/components/PurpleAppBar.js: Unexpected token (5:34)
    3 | import theme from './PurpleAppBar.css';
    4 | 
  > 5 | const PurpleAppBar = ({ children, ...other }) => (
      |                                   ^
    6 |   <AppBar {...other} theme={theme}>
    7 |     Hello developer!
    8 |     {children}

我的jest.config.js

{
"moduleFileExtensions": [
    "js",
    "jsx"
],
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"moduleNameMapper": {
    "App": "<rootDir>/src/frontend/components/App.js"
}

}

我的.bablerc

 {
  "presets": [
     "react",
     "es2015"
  ]
}

package.json脚本:

...    
"scripts": {
        "start": "node_modules/.bin/cross-env NODE_ENV=development node_modules/.bin/webpack-dev-server --colors --config webpack.config.js",
        "build": "node_modules/.bin/cross-env NODE_ENV=production UV_THREADPOOL_SIZE=100 webpack --config webpack.config.js",
        "deploy": "gh-pages -d build",
        "test": "jest --config jest.config.js"
      },
...

1 个答案:

答案 0 :(得分:0)

我找到了答案here

将“stage-3”添加到.babelrc:

{
  "presets": ["es2015", "stage-3", "react"]
}