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 ?
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).