title: How to test url change with Jest
body: <p>I have the following function to test</p>
  <pre class="lang-js prettyprint-override"><code>function tradePage() {
    setTimeout(function() {
      window.location.pathname = document
        .getElementById('button')
        .getAttribute('new-page');
    }, 100);
  }
  </code></pre>
  <p>And I've written the following test:</p>
  <pre class="lang-js prettyprint-override"><code>test('should change page when button is clicked', () =&gt; {
    var button = document.querySelector('#button');
  
    jest.useFakeTimers();
    button.dispatchEvent(createEvent('click'));
    jest.runAllTimers();
  
    expect(window.location.pathname).toEqual('/new-url');
  });
  </code></pre>
  <p>But when I run the test I get this error:</p>
  <pre class="lang-none prettyprint-override"><code>    expect(received).toEqual
      Expected value to equal:
      &quot;/new-url&quot;
      Received:
      &quot;blank&quot;
  </code></pre>
  <p><strong>Things I've already done/tried</strong></p>
  <ul>
  <li><p>My packages.json already have the <code>&quot;testURL&quot;</code> set up.</p>
  </li>
  <li><p>I found this possible solution (that didn't work):</p>
  <pre><code> Object.defineProperty(window.location, 'pathname', {
     writable: true,
     value: '/page/myExample/test',
   });
  </code></pre>
  </li>
  </ul>
  <p>Any ideas what else I can try?</p>