'Verify number of times window.close was called - cypress
I have created stub for window.close for cypress I want to know number of times it has been called .
cy.window().then(win => {
cy.stub(win, 'close').as('parentWindowCalled');
});
I want to check whether window.close is never called . How can I do that ?
Solution 1:[1]
You would need the stub object
let stub
cy.window().then(win => {
stub = cy.stub(win, 'close').as('parentWindowCalled');
})
// actions
cy.wait('@parentWindowCalled')
cy.wait('@parentWindowCalled')
cy.wait('@parentWindowCalled')
cy.then(() => expect(stub).to.have.been.called.exactly(3))
to.have.been.called is just extracting the call count from the spy, so you can chain other criteria like .have.been.called.at.least(3).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kegne |
