https://cypress.io logo
```js Cypress.Commands.add("wrapWindowOpen", (targ...
# general-chat
p
Copy code
js
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
Copy code
cy.get("@open").should("have.been.calledOnce");
Or you can edit the html code not to open it in a new tab