我的目标是测试用jsx编写的reactjs代码和mocha作为测试运行器,酶和chai。目前我收到unexpectet token
错误
我已经在mocha-will-not-recognise-jsx内尝试了解决方案,但它并没有解决我的错误。
{
"scripts": {
"test": "mocha --recursive application/**/*.spec.js* --compilers js:babel-register",
},
[
...
],
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"enzyme": "^2.9.1",
"html-webpack-plugin": "^2.30.1",
"mocha": "^3.5.0",
"standard": "^10.0.3",
"webpack": "^3.5.5",
"webpack-dev-server": "^2.7.1"
}
}
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'env']
}
}]
}
D:\Development\game-of-life\node_modules\babel-core\lib\transformation\file\index.js:59
0
throw err;
^
SyntaxError: D:/Development/game-of-life/application/src/components/app/App.spec.jsx: U
nexpected token (8:28)
6 | describe('App', () => {
7 | it('renders "<div>Application is running</div>"', () => {
> 8 | const wrapper = shallow(<App />)
| ^
9 | expect(wrapper.contains(<div>Application is running</div>)).to.be.eql(true)
10 | })
11 | })
我是否忘记安装软件包或者软件包的较新版本与软件包的旧版本的工作方式不同,因为我已经意识到具有相同依赖性的反应酶项目。
答案 0 :(得分:0)
我找到了两种解决问题的可行方法
使用配置.babelrc
添加presets: ['react', 'env']
。
添加配置(babelrc: false
)以避免.babelrc
并使用webpack配置