Reputation: 6364
When a certain UI bug appears, an alert pops up with an error message. I fixed that bug, and now I want to write a Cypress test.
How do I write a Cypress test that passes if the alert does not appear?
I realize that I must be careful with negative assertions, so I'll want to make the test as robust as possible.
Related post: Cypress: Test if element does not exist
Upvotes: 0
Views: 1486
Reputation: 6364
How do I write a Cypress test that passes if the alert does not appear?
window:alert
event.// Typing enter should not produce an alert
let spy = cy.spy(window, 'alert');
cy.get('input[name="MyField"]')
.type('{enter}')
.wait(4000)
.then(() => {
expect(spy).to.haveOwnProperty('callCount');
expect(spy).to.not.be.called;
});
Upvotes: 2