mardi 10 juillet 2018

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. 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:

"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

 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):

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 } });
      })
    });

Aucun commentaire:

Enregistrer un commentaire