2017-04-08 81 views
0

我嘗試用react-tool-box創建應用程序。我也嘗試使用Jest進行測試,反應Jest ES6(休息傳播運營商)巴貝爾配置不起作用

但得到這個測試失敗。它看起來像是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" 
     }, 
... 

回答

0

我找到答案here

添加 「階段3」 .babelrc:

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