Javascript 开玩笑的意外标记(15:29)<&引用;
我让jest在我的react应用程序上工作,我正在尝试运行测试,但我遇到了一个错误。当我使用Javascript 开玩笑的意外标记(15:29)<&引用;,javascript,reactjs,jestjs,Javascript,Reactjs,Jestjs,我让jest在我的react应用程序上工作,我正在尝试运行测试,但我遇到了一个错误。当我使用“scripts”:{“test”:“react scripts test--env=jsdom”}运行测试时,几乎每个测试都能工作。我不得不将我的测试仪更改为“test”:“jest”以使最后一个测试正常工作,但现在测试在编译时崩溃,因为
“scripts”:{“test”:“react scripts test--env=jsdom”}
运行测试时,几乎每个测试都能工作。我不得不将我的测试仪更改为“test”:“jest”
以使最后一个测试正常工作,但现在测试在编译时崩溃,因为shallow()
抛出了一个错误
从我对代码的理解来看,我的测试应该很好。我必须在project.json文件中设置jest来修复此错误吗
试验
您缺少处理JSX的一个步骤。如果您正在使用babel,请将
react
预设添加到.babelrc
文件中。更多信息可在此处找到:测试现在已编译,但jest说测试在
import {shallow, mount, configure} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import ReactDOM from 'react-dom';
import jest from 'jest';
import ReactPage from './App';
configure({ adapter: new Adapter() });
it('renders ReactPage without crashing', () => {
const div = document.createElement('div');
ReactDOM.render( <ReactPage /> , div);
ReactDOM.unmountComponentAtNode(div);
});
{
"name": "client-charts",
"version": "0.1.0",
"private": true,
"dependencies": {
"async": "^2.6.1",
"moment": "^2.22.2",
"react": "^16.4.2",
"react-dom": "^16.4.1",
"react-scripts": "1.1.4",
"recharts": "^1.1.0",
"react-table": "^6.8.6",
"react-snapshot": "^1.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build && react-snapshot",
"test": "jest",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000",
"devDependencies": {
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"jest": "^20.0.4"
}
}