title: How to access the history object in Jest
body: <p>I have an if conditional that looks like this:</p>
  
  <pre><code>if (history.state !== null &amp;&amp; history.state.query)
  </code></pre>
  
  <p>The issue is that while this doesn't work in Jest, as <code>history</code> is an empty object in my tests.</p>
  
  <p>What needs to be done in my tests to use the <code>history</code> object? I'm running this using React on a Node.js server. Not sure if this matters, but I'm also using React Router.</p>
  
  <p>Test case:</p>
  
  <pre><code>beforeEach(() =&gt; {
    window.ga = jest.fn();
    window.analytics = jest.fn();
    window.analytics.track = jest.fn();
  });
  
  it('should set up props from history state', () =&gt; {
    let location = {
      pathname: '/explore',
      query: {
        query: 'yahoo',
      },
    };
  
    global.history = { state: { query: 'google'} };
  
    const wrapper = mount(
      &lt;LandingPage location={location} /&gt;
    );
  
    console.log("global.history.state: " + global.history.state); // prints null
  });
  </code></pre>
  
  <p>Part of the component (can't put the whole component):</p>
  
  <pre><code>if (props.location &amp;&amp; props.location.pathname === '/explore') {
    explorePath = true;
    skipIntro = true;
    explore = true;
  
    /* checks if history.state is not equal to null
     * if check passes, search query and results will appear
     */
    if (history.state !== null &amp;&amp; history.state.query) {
      currentValue = history.state.query;
      employeeMin = history.state.eMin;
      employeeMax = history.state.eMax;
      revenueMin = history.state.rMin;
      revenueMax = history.state.rMax;
    }
  } else {
    explore = skipIntro;
  }
  </code></pre>