powerful-orange-86819
01/10/2023, 8:04 AMjs
Cypress.Commands.add("wrapWindowOpen", (target = undefined) => {
cy.window().then((win) => {
cy.stub(win, "open")
.callsFake((url, target) => {
if (target === undefined) {
expect(target).to.be.undefined;
} else {
expect(target).to.eq("_blank");
}
return win.open.wrappedMethod.call(win, url, "_self");
})
.as("open");
});
});
This is my custom command that I add in the beforeEach() and then just assert it with
cy.get("@open").should("have.been.calledOnce");
Or you can edit the html code not to open it in a new tab