Hi, i'm testing a component with mount:
when I try to create the wrapper
import React from 'react';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
const middlewares = [ thunk ];
const mockStore = configureStore( middlewares );
const initState = {};
const store = mockStore( initState );
store.dispatch = jest.fn();
const wrapper = mount(
<Provider store={ store } >
<DeleteEventFab />
</Provider>
)
throws this error
TypeError: Cannot read property 'child' of undefined
25 |
26 |
> 27 | const wrapper = mount(
| ^
28 | <Provider store={ store } >
29 | <DeleteEventFab />
30 | </Provider>
at getFiber (node_modules/enzyme-adapter-react-16/src/detectFiberTags.js:15:35)
at detectFiberTags (node_modules/enzyme-adapter-react-16/src/detectFiberTags.js:76:15)
at ReactSixteenAdapter.createMountRenderer (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:465:19)
at ReactSixteenAdapter.createRenderer (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:820:51)
at new ReactWrapper (node_modules/enzyme/src/ReactWrapper.js:113:32)
at mount (node_modules/enzyme/src/mount.js:10:10)
at Object.<anonymous> (src/tests/components/DeleteEventFab.test.js:27:17)
If I downgrade react to version
"react": "^16.13.1",
"react-dom": "^16.13.1"
this same code works perfect
It should create the wrapper son I can make an expect( wrapper ).toMatchSnapshot();
"react": "^17.0.1",
"react-dom": "^17.0.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
"enzyme-to-json": "^3.6.1",
enzyme is not yet compatible with React 17 - you're using the React 16 adapter, and that requires react 16.
See #2429 for that support.
Most helpful comment
enzyme is not yet compatible with React 17 - you're using the React 16 adapter, and that requires react 16.
See #2429 for that support.