Enzyme: TypeError: Cannot read property '_compositeType' of null

Created on 28 Sep 2017  路  7Comments  路  Source: enzymejs/enzyme

While using React 15.6.1 and enzyme-adapter-react-15 I'm getting this error while using a simple shallow test:

it('should have div element', () => {
  function Foo() {
    return <div />;
  }
  const wrapper = shallow(<Foo />);
  expect(wrapper.type()).toBe('div');
});

TypeError: Cannot read property '_compositeType' of null

moving forward to enzyme-adapter-react-16, the issue is resolved. Yet, I'm not using React-16.

Need To Reproduce v3 bugs

Most helpful comment

@jony89 I had the same issue until I changed the react-test-renderer dependency version from 16.0.0 to 15.6.1.

All 7 comments

Can you provide a repro repo?

@jony89 I had the same issue until I changed the react-test-renderer dependency version from 16.0.0 to 15.6.1.

Indeed, every react thing needs to have the same major and minor versions.

@ljharb i think in some cases this isn't true, such as prop-types and create-react-class. Just FYI to anyone reading.

True, to clarify: every "react-"-prefixed thing, and React itself.

Installing react-test-renderer@15.6.1 did fix the problem.

Using npm ls it's possible to see peerDependencies and identify the issue easly.

npm install [email protected] suggested above fixed the problem.

Was this page helpful?
0 / 5 - 0 ratings