title: Setting up Jest and Enzyme to test React 15 cannot find module react/lib/ReactTestUtils
body: <p>I have a react project and am trying to setup some tests</p>
  
  <p>Due to the following setup guides / issues:</p>
  
  <ul>
  <li><a href="https://github.com/facebook/jest/issues/1353" rel="noreferrer">https://github.com/facebook/jest/issues/1353</a> ,</li>
  <li><a href="https://github.com/facebook/react/issues/7386" rel="noreferrer">https://github.com/facebook/react/issues/7386</a> ,</li>
  <li><a href="http://facebook.github.io/jest/docs/tutorial-react.html#content" rel="noreferrer">http://facebook.github.io/jest/docs/tutorial-react.html#content</a> ,</li>
  <li><a href="http://airbnb.io/enzyme/" rel="noreferrer">http://airbnb.io/enzyme/</a></li>
  </ul>
  
  <p>I have installed the following dependencies:</p>
  
  <ul>
  <li>react-addons-test-utils 15.3.2</li>
  <li>react 15.4.0-rc.4</li>
  <li>react-dom 15.4.0-rc-4</li>
  <li>jest 16.0.2</li>
  <li>babel-jest 16.0.0</li>
  <li>babel-preset-es2015 6.18.0 </li>
  <li>babel-preset-es2015-loose 7.0.0</li>
  <li>babel-preset-react 6.16.0</li>
  </ul>
  
  <p>My package.json contains the following Jest configuration:</p>
  
  <pre><code> "jest": {
      "bail": false,
      "collectCoverage": true,
      "collectCoverageFrom": [
        "&lt;rootDir&gt;/src/**/*.js",
        "!&lt;rootDir&gt;/node_modules/**"
      ],
      "coverageDirectory": "coverage",
      "coveragePathIgnorePatterns": [
        "&lt;rootDir&gt;/node_modules"
      ],
      "coverageThreshold": {
        "global": {
          "branches": 50,
          "functions": 50,
          "lines": 50,
          "statements": 50
        }
      },
      "globals": {
        "SOURCEMAP": true
      },
      "modulePaths": [
        "&lt;rootDir&gt;/src",
        "&lt;rootDir&gt;/sass",
        "&lt;rootDir&gt;/public",
        "&lt;rootDir&gt;/node_modules"
      ],
      "resetModules": true,
      "testPathDirs": [
        "&lt;rootDir&gt;/test"
      ],
      "testRegex": "(/test/.*|\\.(test|spec))\\.(js|jsx)$",
      "verbose": true
    }
  </code></pre>
  
  <p>I have my component (GenericButton) placed in <code>&lt;rootDir&gt;/components/buttons/GenericButton.js</code> and my test in <code>&lt;rootDir&gt;/test/componnets/buttons/GenericButtonTest.js</code> with contents as following:</p>
  
  <pre><code>import React from 'react';
  import GenericButton from 'components/buttons/GenericButton';
  import { shallow } from 'enzyme';
  import { shallowToJson } from 'enzyme-to-json';
  import ReactTestUtils from 'react-addons-test-utils'
  
  describe('Generic Button', () =&gt; {
      test('Button action called when clicked', () =&gt; {
          var clicked = false;
          const component = shallow(
              &lt;GenericButton action={() =&gt; {
                  clicked = true;
              }}/&gt;
          );
  
          console.log("Clicking the button!");
          ReactTestUtils.Simulate.click(component);
          expect(clicked).toBeTruthy();
      });
  })
  </code></pre>
  
  <p>My babelrc file is as follows:</p>
  
  <pre><code>{
    "presets": [
      "es2015-loose",
      "react",
      "stage-0"
    ],
    "plugins": [
      "babel-root-slash-import",
      "transform-decorators-legacy",
      "react-hot-loader/babel",
      "transform-runtime"
    ],
    "compact": true,
    "ignore": [
      "/node_modules/(?!react-number-input)"
    ]
  }
  </code></pre>
  
  <p>when I run my test however, I get the following error:</p>
  
  <pre><code>&gt; admin-console@4.1.0 test C:\path\to\project
  &gt; jest
  
   FAIL  test\components\buttons\GenericButtonTest.js
    ● Test suite failed to run
  
      Cannot find module 'react/lib/ReactTestUtils' from 'index.js'
  
        at Resolver.resolveModule (node_modules\jest-resolve\build\index.js:144:17)
        at Object.&lt;anonymous&gt; (node_modules\react-addons-test-utils\index.js:1:107)
        at node_modules\enzyme\build\react-compat.js:128:19
  
  ----------|----------|----------|----------|----------|----------------|
  File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
  ----------|----------|----------|----------|----------|----------------|
  All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
  ----------|----------|----------|----------|----------|----------------|
  Test Suites: 1 failed, 1 total
  Tests:       0 total
  Snapshots:   0 total
  Time:        5.843s
  Ran all test suites.
    console.error node_modules\enzyme\build\react-compat.js:131
      react-addons-test-utils is an implicit dependency in order to support react@0.13-14. Please add the appropriate version to your devDependencies. See https://github.com/airbnb/enzyme#installation
  
  npm ERR! Test failed.  See above for more details.
  </code></pre>
  
  <p>What can I do to make this simple test pass?</p>
  
  <hr>
  
  <p>Edit: The file react/lib/ReactTestUtils which react-addons-test-utils is requiring is not in the node_modules/react/lib folder. </p>
  
  <p>This was fixed by upgrading react-addons-test-utils to 15.4.0-rc.3 but then I got:</p>
  
  <pre><code>TypeError: Cannot read property '__reactInternalInstance$t476n6b4jes0zxw0n18vbzkt9' of undefined
  
    at getClosestInstanceFromNode (node_modules\react-dom\lib\ReactDOMComponentTree.js:106:11)
    at Object.getInstanceFromNode (node_modules\react-dom\lib\ReactDOMComponentTree.js:140:14)
    at Object.click (node_modules\react-dom\lib\ReactTestUtils.js:326:74)
    at Object.&lt;anonymous&gt; (test\components\buttons\GenericButtonTest.js:17:67)
  </code></pre>