这很简单。在我的React应用程序中,我想与Jest一起使用Enzyme来测试我的应用程序。我已经为酶创建了一个设置文件
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
Enzyme.configure({ adapter: new Adapter() });
,并将这一行添加到jest配置文件中:
"setupTestFrameworkScriptFile": "<rootDir>/test/setupEnzyme.js"
我无法进行任何测试。从字面上看,所有测试(甚至是最基本的测试,如果2 + 2为4的测试)都会失败并返回
FAIL test/app.test.js
● Test suite failed to run
TypeError: The super constructor to "inherits" must have a prototype
at Object.<anonymous> (node_modules/parse5/lib/extensions/position_tracking/preprocessor_mixin.js:29:1)
at Object.<anonymous> (node_modules/parse5/lib/extensions/location_info/tokenizer_mixin.js:5:41)
at Object.<anonymous> (node_modules/parse5/lib/extensions/location_info/parser_mixin.js:5:34)
at Object.<anonymous> (node_modules/parse5/lib/parser/index.js:6:31)
最基本的测试(在添加酶之前,该测试效果很好)
describe('App', () => {
it('should be able to run tests', () => {
expect(1 + 2).toEqual(3);
})
});
反应组件(TextField使用material-ui)
import React from 'react';
import { shallow } from 'enzyme';
import TextField from 'components/Pages/FormElements/TextField'
import getMuiTheme from 'material-ui/styles/getMuiTheme';
const muiTheme = getMuiTheme();
describe('Text Field', () => {
it('renders without crashing', () => {
const wrapper = shallow(<TextField />, { context: { muiTheme },
childContextTypes: { muiTheme: React.PropTypes.object } });
})
});
答案 0 :(得分:0)
尝试使用设置setupTests.js
命名文件