title: How do I configure jsdom with jest
body: <p>I have installed jest and jsdom into my react project but I am having problems with importing a react component that uses the <code>window.localStorage</code> variable. I have added a setup file for jsdom that I believed would solve the problem.</p>
  
  <p>Here is my setup:</p>
  
  <p>jest config in package.json</p>
  
  <pre><code>"jest": {
      "verbose": true,
      "testEnvironment": "jsdom",
      "testURL": "http://localhost:8080/Dashboard/index.html",
      "transform": {
        "^.+\\.js$": "&lt;rootDir&gt;/node_modules/babel-jest",
        "^.+\\.jsx$": "&lt;rootDir&gt;/node_modules/babel-jest"
      },
      "unmockedModulePathPatterns": [
        "node_modules/react/",
      ],
      "moduleFileExtensions": [
        "js",
        "jsx",
        "json",
        "es6"
      ]
    }
  </code></pre>
  
  <p>setup.js</p>
  
  <pre><code>import jsdom from 'jsdom';
  
  const DEFAULT_HTML = '&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;';
  
  global.document = jsdom.jsdom(DEFAULT_HTML);
  
  global.window = document.defaultView;
  global.navigator = window.navigator;
  global.localStorage = window.localStorage;
  </code></pre>
  
  <p>test.js</p>
  
  <pre><code>'use strict';
  import setup from './setup';
  import React from 'react';
  import jsdom from 'jsdom';
  import Reportlet from '../components/Reportlet.jsx';
  
  it('Ensures the react component renders', () =&gt; {
  
  });
  </code></pre>
  
  <p>My reportlet component uses the localStorage variable but yells:</p>
  
  <p><code>Cannot read property getItem of undefined</code> when I call <code>localStorage.getItem(&lt;some item&gt;)</code></p>
  
  <p>I read <a href="http://facebook.github.io/jest/docs/tutorial-jquery.html#docsNav" rel="noreferrer">here</a> that jest comes shipped with jsdom but I am not sure if I need the extra jsdom dependency or not. I also read <a href="http://airbnb.io/enzyme/docs/guides/jsdom.html" rel="noreferrer">here</a> that jsdom needs to be loaded before requiring react for the first time. </p>
  
  <p>Does anyone know how to configure jest with jsdom correctly?</p>