0

After clicking an image in my application a new tab is getting opened with different domain URL, but I am getting below error

Code -

cy.window().then((win) => {
   cy.spy(win, 'open').as('@redirect')
});

cy.get('webElement').click();
cy.get('@redirect').should('be.called')

Note: 
1. webElement clicked is 'img' not anchor and it does not have any 'href' and 'target' attribute.
2. Same code is working fine when new tab url is of same domain.

DOM Error

Mitu
  • 1

1 Answers1

0

The alias should not be named @redirect but redirect:

cy.spy(win, 'open').as('@redirect')

Correct:

cy.spy(win, 'open').as('redirect')

You are asserting it correctly.

https://docs.cypress.io/api/commands/as#DOM-element

PaulGrant
  • 358
  • 3
  • 9