简体   繁体   English

添加酶用于React测试后,所有测试均失败

[英]After adding enzyme for React testing all tests fail

This is pretty straight forward. 这很简单。 In my React app I want to use Enzyme alongside Jest to test my application. 在我的React应用程序中,我想与Jest一起使用Enzyme来测试我的应用程序。 I've created a setup file for Enzyme 我已经为酶创建了一个安装文件

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';

Enzyme.configure({ adapter: new Adapter() });

and also added this line to jest config file: 并将此行添加到jest配置文件中:

"setupTestFrameworkScriptFile": "<rootDir>/test/setupEnzyme.js"

I can't get any tests to work. 我无法进行任何测试。 Literally all tests (even most basic ones testing if 2+2 is 4) fail and return 从字面上看,所有测试(甚至是最基本的测试,如果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)

Most basic test (this one worked fine before adding enzyme): 最基本的测试(此方法在添加酶之前效果很好):

describe('App', () => {
  it('should be able to run tests', () => {
    expect(1 + 2).toEqual(3);
  })
});

React component (TextField uses material-ui): React组件(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 } });
  })
});

尝试使用安装程序setupTests.js命名文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM