Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 of 4 tasks
marianolop22 opened this issue Oct 25, 2020 · 7 comments
Closed
2 of 4 tasks

Comments

@marianolop22
Copy link

marianolop22 commented Oct 25, 2020

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
  • 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

  • enzyme-adapter-react-16
@ljharb
Copy link
Member

ljharb commented Oct 25, 2020

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.

@ljharb ljharb closed this as completed Oct 25, 2020
llama90 added a commit to llama90/frontend-snippet that referenced this issue Dec 28, 2020
  It processes all the descendent components.

  Issue: enzyme is not yet compatible with React 17
  ref: enzymejs/enzyme#2462

  How to check the React version on the project
  The package.json contains `"react": "^17.0.1",`
  ref: https://www.positronx.io/how-to-check-react-app-version-quickly/
@JackDan9

This comment has been minimized.

@pavanjava

This comment has been minimized.

@ljharb

This comment has been minimized.

@pavanjava

This comment has been minimized.

@ljharb

This comment has been minimized.

@pavanjava

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants