我正在使用Mocha运行此测试,并在我的npm package.json
中进行以下配置 "scripts": {"test": "mocha './app/**/*.spec.js' --compilers js:babel-core/register"}
,这会导致以下错误
employeeGrid.row.spec.jsx:意外的令牌(8:12)
请注意,第8:12行是以下内容:return (<tr>
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import expect from 'expect-jsx';
//import GridRow from './employeeGrid.row.jsx'
class GridRow extends React.Component {
render() {
return (<tr>
<td>{this.props.employee.name}</td>
<td>{this.props.employee.position}</td>
<td>{this.props.employee.yearStarted}</td>
</tr>)
}
}
describe('Grid Row', () => {
it('Row Actions Test', ()=> {
let employee = {
"name": "Person",
"position": "Software Engineer",
"yearStarted": 2010
};
// shallow render
// renders only one level deep
const renderer = TestUtils.createRenderer();
renderer.render(<GridRow employee={employee}/>);
const output = renderer.getRenderOutput();
console.log(output);
});
});
知道我做错了吗?
答案 0 :(得分:1)
使用babel 6.0时,默认情况下不再处理JSX,也不会使用es2015
预设处理JSX。您需要专门使用react
预设来获得适当的JSX转换:
$ npm install babel-preset-react
和您的.babelrc
:
{
"presets": ["es2015", "react"]
}