title: Cypress: Stub open window
body: <p>in my app there is an recommendations list, which on click opens a new window with a dynamic address:</p>
  
  <pre><code>$window.open(_shopURL, '_blank');
  </code></pre>
  
  <p>Now I'm trying to stub the windows.open event as shown in <a href="https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/stubbing-spying__window/cypress/integration/window-stubbing.spec.js" rel="noreferrer">https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/stubbing-spying__window/cypress/integration/window-stubbing.spec.js</a></p>
  
  <pre><code>Cypress.on('window:before:load', (win) =&gt; {
   win.open = cy.stub().as('windowOpen')
  })
  
  
  describe('Shop integration', () =&gt; {
   beforeEach(function () {
    cy.visitHome(countryCode, resellerId)
   })
  
  it('can stub the window open event', function () {
    cy.get(`.recommendations-list .recommendations-cover:nth-of-type(1)`)
      .click()
    cy.get('@windowOpen').should('be.calledWith', 'page1.html')
  })
  </code></pre>
  
  <p>But it's always opening the new tab and the logs are wrong:
  <a href="https://i.stack.imgur.com/6waG0.png" rel="noreferrer">Cypress: stub open window</a></p>
  
  <p>Does anybody has an idea why it's not working?
  Cheers!</p>