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.
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.
Most helpful comment
@jony89 I had the same issue until I changed the
react-test-rendererdependency version from 16.0.0 to 15.6.1.