How test redirect in Cypress implemented with window.open

Viewed 219

How to test the redirection implemented with window.open?

What am i doing wrong? I want to intercept redirection implemented by window.open().

  it("Form is opened", () => {
    cy.visit(`http://localhost:28080/app/form`, {
      onBeforeLoad(win) {
        cy.stub(win, 'open').as('windowOpen');
      }
    });
  });
... 
  describe("Field test", () => {

      redirectButton().click();
      cy.get('@windowOpen').then($w => {
        debugger;
      })
    });

But onClick on RedirectButton Cypress redirects to no-test page that says Whoops, there is no test to run.

enter image description here

But if I change my redirectButton implementation from window.open to location.href it redirects to the correct page and finishes this test successfully.

I tried on Cypress 3.8 and 4.9

0 Answers
Related