I want to test that closing a tab (or reloading the tab) results in a confirmation box being displayed. If the user clicks ‘cancel’, the confirmation box should disappear and the page didn’t reload.
I tried to test this with something like this:
cy.on('window:confirm', () => false)
cy.reload()
However, this fails – the page just reloads & the confirmation box doesn’t appear. (The confirmation box is definitely working).
2
Answers
Here is another work around, that I ever used
I may be a good solution for you.
Try stubbing the
window:confirm
and verifying the stub has been called: