title: Jest error - Not implemented: navigation (except hash changes) when click event is triggered on an anchor element
body: <p>I have written unit test using jest version <code>26.0.0</code> with react-testing-library and node version <code>14.2.0</code>. Below is my React functional component which has a button, on clicking makes an ajax call to download a report file.</p>
  <pre class="lang-js prettyprint-override"><code>const ReportListTable = () =&gt; {
      const { downloadReports } = useReports();
  
      const onClickDownload = () =&gt; {
          let fileName = `Report.zip`;
          downloadReports()
              .then((response) =&gt; response.arrayBuffer())
              .then((data) =&gt; {
                  const blob = new Blob([data], { type: &quot;octet/stream&quot;, endings: &quot;native&quot; });
                  const url = window.URL.createObjectURL(blob);
                  const anchor = document.createElement(&quot;a&quot;);
                  anchor.setAttribute(&quot;href&quot;, url);
                  anchor.setAttribute(&quot;download&quot;, fileName);
                  anchor.click();
                  window.URL.revokeObjectURL(url);
              })
              .catch((error?: Error | Response) =&gt; {
                  if (error instanceof Error) {
                      message.error(error?.message);
                  }
              });
      };
  
      return (
          &lt;div&gt;
              &lt;Button data-testid=&quot;download-btn&quot; onClick={onClickDownload}&gt;
                  Download
              &lt;/Button&gt;
          &lt;/div&gt;
      );
  };
  </code></pre>
  <p>And I have below test suite where the <code>createObjectURL</code> and <code>revokeObjectURL</code> before the test runs.</p>
  <pre class="lang-js prettyprint-override"><code>describe(&quot;Test Reports List Table component&quot;, () =&gt; {
      const { URL } = window;
  
      beforeAll(() =&gt; {
          window.URL.createObjectURL = jest.fn();
          window.URL.revokeObjectURL = jest.fn();
  
          jest.spyOn(useReportsHook, &quot;useReports&quot;).mockReturnValue(useReportsMockValue);
      });
  
      afterAll(() =&gt; {
          window.URL = URL;
          jest.clearAllMocks();
      });
  
      it(&quot;should handle row button enabled and download on button clicked&quot;, async () =&gt; {
          jest.spyOn(useReportsContextHook, &quot;useReportsContext&quot;).mockReturnValue([{ checkedIds: [&quot;report_1&quot;] }, jest.fn]);
          const { asFragment } = render(&lt;ReportListTable /&gt;);
          
          fireEvent.click(await screen.getByTestId(elements.downloadTestId));
          await waitFor(() =&gt; expect(window.URL.createObjectURL).toHaveBeenCalled());
          await waitFor(() =&gt; expect(window.URL.revokeObjectURL).toHaveBeenCalled());
          expect(asFragment).toMatchSnapshot();
      });
  });
  </code></pre>
  <p>The test case is passed however it throws the below error.</p>
  <pre class="lang-js prettyprint-override"><code>  console.error
      Error: Not implemented: navigation (except hash changes)
          at module.exports (/Users/user/Documents/lydia-github/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)
          at navigateFetch (/Users/user/Documents/lydia-github/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/window/navigation.js:76:3)
          at exports.navigate (/Users/user/Documents/lydia-github/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/window/navigation.js:54:3)
          at Timeout._onTimeout (/Users/user/Documents/lydia-github/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/nodes/HTMLHyperlinkElementUtils-impl.js:81:7)
          at listOnTimeout (internal/timers.js:549:17)
          at processTimers (internal/timers.js:492:7) undefined
  </code></pre>
  <p>I tried to mock the <code>location</code> object after referring this thread <a href="https://stackoverflow.com/questions/54090231/how-to-fix-error-not-implemented-navigation-except-hash-changes">How to fix Error: Not implemented: navigation (except hash changes)</a>, however it didn't help. I need help to resolve this error.</p>