Cypress · Middle · Question 25 of 77
How do you test that window.open was called with the right URL?
cy.window().then((win) => {
cy.stub(win, "open").as("open");
});
cy.contains("Share").click();
cy.get("@open").should("be.calledWith", "https://example.com/share");- 1Wait for a new tab and check its URL
- 2Read the URL from the browser history
- 3Stub
win.openand assert on the alias
Show the answer
Correct answer: Stub win.open and assert on the alias
Explanation
Stubbing replaces the real call, so no tab opens, and Sinon assertions check the arguments.