enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.96k stars 2.01k forks source link

Cannot read property 'child' of undefined on React 16 + enzyme-adapter-react-16 #2562

Open dep opened 2 years ago

dep commented 2 years ago

Current behavior

import React from "react";
import { mount } from "enzyme";
import NewTagModal from "./NewTagModal";

describe("New Tag Modal", () => {
  let component;
  function mountComponent() {
    return mount(
      <NewTagModal isOpen={true} />;
    );
  }

  beforeEach(() => {
    component = mountComponent();
  });

  it("has a title", () => {
    expect(component.find("h4").text()).toBe("Create New Tag");
  });
});

Returns:

    TypeError: Cannot read property 'child' of undefined

      72 |
      73 |   function mountComponent() {
    > 74 |     return mount(

      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 ReactSixtee^C

Expected behavior

Tests pass

API

Version

library version
enzyme 3.11.0
react 16.4.0
react-dom 16.4.0
react-test-renderer n/a
adapter (below) enzyme-adapter-react-16

Adapter

ljharb commented 2 years ago

Can you try React v16.4.2?