Enzyme: Cannot use `mount`

Created on 22 May 2019  路  4Comments  路  Source: enzymejs/enzyme

Current behavior

Test.js

beforeEach(() => {
  wrapper = mount(<div />);
});

Terminal output

TypeError: Cannot read property '_reactInternalFiber' of null

      11 |
      12 |   beforeEach(() => {
    > 13 |     wrapper = mount(<div />);
         |               ^
      14 |
      15 |     console.log(wrapper.debug());
      16 |   });

      at _reactInternalFiber (node_modules/enzyme-adapter-react-16/src/detectFiberTags.js:15:15)
      at getFiber (node_modules/enzyme-adapter-react-16/src/detectFiberTags.js:76:15)
      at ReactSixteenAdapter.createMountRenderer (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:396:19)
      at ReactSixteenAdapter.createMountRenderer [as createRenderer] (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:702:51)
      at new ReactWrapper (node_modules/enzyme/build/ReactWrapper.js:132:30)
      at mount (node_modules/enzyme/build/mount.js:21:10)
      at Object.beforeEach (src/components/misc/ScrollToTop/ScrollToTop.test.js:13:15

Expected behavior

It should mount and run

Your environment

macOS 10.14.4 (18E226)
VSCode 1.34.0 (1.34.0)

Used create-react-app to build app

API

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

Version

| library | version
| ------------------- | -------
| enzyme | 3.9.0
| react | 16.8.6
| react-dom | 16.8.6
| react-test-renderer | 16.8.6
| adapter (below) | 1.13.1

Adapter

  • [x] enzyme-adapter-react-16
  • [ ] enzyme-adapter-react-16.3
  • [ ] enzyme-adapter-react-16.2
  • [ ] enzyme-adapter-react-16.1
  • [ ] enzyme-adapter-react-15
  • [ ] enzyme-adapter-react-15.4
  • [ ] enzyme-adapter-react-14
  • [ ] enzyme-adapter-react-13
  • [ ] enzyme-adapter-react-helper
  • [ ] others ( )

Just to note, shallow(<div />) works just fine, however I need deeper access in this one test.

invalid

Most helpful comment

Okay so it turns out I was mocking react-dom in a _really_ bad way. A copy/paste jobber from StackOverflow. I have other problems to solve now, but this was not your libraries fault.

All 4 comments

Tried on a blank create-react-app and everything worked just fine, but as soon as I copied my components over it broke hard. Not entirely sure what's going on here, I didn't install any of the extra dependencies aside from react-router-dom, just ran the same test.

This seems like the same issue as #2110.

I saw that (only after I created this, sorry). Nothing in there could help me 馃槬

Okay so it turns out I was mocking react-dom in a _really_ bad way. A copy/paste jobber from StackOverflow. I have other problems to solve now, but this was not your libraries fault.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

modemuser picture modemuser  路  3Comments

potapovDim picture potapovDim  路  3Comments

AdamYahid picture AdamYahid  路  3Comments

ahuth picture ahuth  路  3Comments

thurt picture thurt  路  3Comments