Enzyme: When using mount: Cannot read property 'child' of undefined on React 17

Created on 25 Oct 2020  路  1Comment  路  Source: enzymejs/enzyme

Hi, i'm testing a component with mount:

Current behavior

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

Expected behavior

It should create the wrapper son I can make an expect( wrapper ).toMatchSnapshot();

Your environment

API

  • [ ] shallow
  • [x] mount
  • [ ] render

Version

"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",

Adapter

  • [x] enzyme-adapter-react-16

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings