title: Error testing react component - SecurityError
body: <p>I'm testing a react HOC which checks if there's a token present in localstorage or not. If there is, it redirects the user to the Home component else the user will be redirected to the Login component.</p>
  <p>However, i'm getting this strange error in the last test where it tests for calling componentDidMount</p>
  <blockquote>
  <p>SecurityError</p>
  <p>at HistoryImpl._sharedPushAndReplaceState (node_modules/jsdom/lib/jsdom/living/window/History-impl.js:87:15)</p>
  <p>at HistoryImpl.pushState (node_modules/jsdom/lib/jsdom/living/window/History-impl.js:69:10)</p>
  <p>at History.pushState (node_modules/jsdom/lib/jsdom/living/generated/History.js:72:31)</p>
  </blockquote>
  <p>here is the test i wrote:</p>
  <p><strong>app.test.js</strong></p>
  <pre><code>import React from 'react'; 
  import { shallow, mount } from 'enzyme';
  import { expect } from 'chai';
  import sinon from 'sinon';
  
  import App from '../containers/App.jsx';
  
  describe('&lt;App /&gt;', () =&gt; {
    beforeAll(() =&gt; {
      global.localStorage = {
        i2x_token: 'someToken',
        getItem() {
          return 'someToken';
        }
      };
    });
  
    it('renders without exploding', () =&gt; {
      shallow(&lt;App /&gt;);
    });
  
    it('renders children when passed in', () =&gt; {
      const wrapper = shallow(
        &lt;App&gt;
          &lt;div className='unique' /&gt;
        &lt;/App&gt;,
     );
      expect(wrapper.contains(&lt;div className='unique' /&gt;)).to.equal(true);
    });
  
   it('calls componentDidMount', () =&gt; {
      sinon.spy(App.prototype, 'componentDidMount');
      const wrapper = mount(&lt;App /&gt;);
      expect(App.prototype.componentDidMount).to.have.property('callCount', 1);
      App.prototype.componentDidMount.restore();
    });
  });
  </code></pre>
  <p>`</p>
  <p>and this is the component itself:</p>
  <p><strong>app.jsx</strong></p>
  <pre><code>import React, { Component } from 'react';
  import { browserHistory } from 'react-router';
  
  class App extends Component {
    componentDidMount() {
      if (localStorage.i2x_token) {
         browserHistory.push('/home');
      } else {
        browserHistory.push('/');
      }
    }
  
    render() {
      return (
        &lt;main&gt;
          {React.Children.toArray(this.props.children)}
        &lt;/main&gt;
      );
    }
  }
  
  App.propTypes = {
    children: React.PropTypes.node,
  };
  
  export default App;
  </code></pre>
  <p>this is my package.json:</p>
  <p><strong>package.json</strong></p>
  <pre><code>  &quot;dependencies&quot;: {
      &quot;express&quot;: &quot;^4.15.2&quot;,
      &quot;react&quot;: &quot;^15.4.2&quot;,
      &quot;react-dom&quot;: &quot;^15.4.2&quot;,
      &quot;react-router&quot;: &quot;3.0.0&quot;,
      &quot;whatwg-fetch&quot;: &quot;^2.0.3&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;babel-core&quot;: &quot;^6.24.1&quot;,
      &quot;babel-jest&quot;: &quot;^19.0.0&quot;,
      &quot;babel-loader&quot;: &quot;^7.0.0&quot;,
      &quot;babel-polyfill&quot;: &quot;^6.23.0&quot;,
      &quot;babel-preset-es2015&quot;: &quot;^6.24.1&quot;,
      &quot;babel-preset-react&quot;: &quot;^6.24.1&quot;,
      &quot;chai&quot;: &quot;^3.5.0&quot;,
      &quot;cross-env&quot;: &quot;^3.1.3&quot;,
      &quot;css-loader&quot;: &quot;^0.28.0&quot;,
      &quot;enzyme&quot;: &quot;^2.8.2&quot;,
      &quot;eslint&quot;: &quot;^3.19.0&quot;,
      &quot;eslint-config-airbnb&quot;: &quot;^14.1.0&quot;,
      &quot;eslint-plugin-import&quot;: &quot;^2.2.0&quot;,
      &quot;eslint-plugin-jsx-a11y&quot;: &quot;^4.0.0&quot;,
      &quot;eslint-plugin-react&quot;: &quot;^6.10.3&quot;,
      &quot;file-loader&quot;: &quot;^0.11.1&quot;,
      &quot;jest&quot;: &quot;^19.0.2&quot;,
      &quot;moment&quot;: &quot;^2.18.1&quot;,
      &quot;moment-timezone&quot;: &quot;^0.5.13&quot;,
      &quot;node-sass&quot;: &quot;^4.5.2&quot;,
      &quot;react-addons-test-utils&quot;: &quot;^15.5.1&quot;,
      &quot;sass-loader&quot;: &quot;^3.2.0&quot;,
      &quot;sinon&quot;: &quot;^2.1.0&quot;,
      &quot;style-loader&quot;: &quot;^0.16.1&quot;,
      &quot;webpack&quot;: &quot;^2.2.1&quot;,
      &quot;webpack-dev-server&quot;: &quot;^2.4.2&quot;
    }
  </code></pre>
  <p>I'm wondering what's wrong. Something do with react router perhaps?</p>