title: How Can I Test A File Download Using Cypress When Running In Chrome
body: <p>I have the following test that needs to verify that clicking a link downloads a PDF. This is especially important as we are using Gatsby, which in turn uses Reach Router's Link Component, and it is relatively easy to misconfigure things so that the router takes over the link and navigates to a 404 page instead of initiating a download.</p>
  
  <pre><code>describe.skip(`Downloads`, () =&gt; {
    it(`Downloads the expected file`, () =&gt; {
      cy.visit(pagePath)
      cy.getByHref(downloadPath)
        .should(`have.attr`, `target`, `_blank`)
        .click()
      cy.location(`pathname`).should(`eq`, pagePath)
    })
  })
  </code></pre>
  
  <p>While this isn't perfect, it does at least check that there is no navigation as a result of clicking the link. </p>
  
  <p>The problem is that when running this test using <code>cy run</code>, which runs the tests in Chrome, the test hangs, due to Chrome's download dialogue.</p>
  
  <p><strong>How can I prevent the test from hanging?</strong></p>
  
  <p>Note that the downloadPath resolves to a pdf in the static directory, for example <code>/static/example.pdf</code>. There is no server component.</p>
  
  <p>Also note that this is a different question to: <a href="https://stackoverflow.com/questions/47930881/how-can-i-use-cypress-io-to-assert-that-a-file-download-has-been-initiated-witho">How can I use Cypress.io to assert that a file download has been initiated without actually downloading?</a></p>