title: Stubbing network request with cypress
body: <p>I am trying to mock a server in some UI tests that I am writing using cypress. I am probably making some basic mistake and might not be understanding how cypress is stubbing requests. Here is an example app that I copied straight from expressjs - </p>
  
  <pre><code>const express = require('express')
  const app = express()
  const port = 3000
  
  app.get('/', (req, res) =&gt; res.send('Hello from /'));
  app.get('/user', (req, res) =&gt; res.send('Hello from /user'));
  
  app.listen(port, () =&gt; console.log(`Example app listening on port ${port}!`));
  </code></pre>
  
  <p>And then wrote a simple test using cypress - </p>
  
  <pre><code>
  describe('Stubbed request', () =&gt; {
    it('sends whatever response you want', () =&gt; {
      cy.visit('http://localhost:3000/');
      cy.server();
      cy.route({
        method: 'GET',
        url: '/user',
        response: [],
      }).as('bar');
  
      cy.visit('http://localhost:3000/user'); // cy.request() has same behavior
      cy.wait('@bar');
    })
  })
  
  </code></pre>
  
  <p>I was hoping that instead of 'Hello from user/', I should get an empty response since I have stubbed it with cypress. Even cy.wait fails with message - "CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'bar'. No request ever occurred." I am obviously doing something wrong. Can someone please help me understand what am I doing wrong? Thanks in advance. </p>