Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
How to assert that an alert does not appear?

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 I can.


Related post: Cypress: Test if element does not exist

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

How do I write a Cypress test that passes if the alert does not appear?


  1. Spy on the window:alert event.
  2. Wait a few seconds to give the alert time to appear.
  3. Use a positive assertion to make sure the spy is what you're expecting.
  4. Assert that the spy isn't called.
// 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;
    });
  1. Also make a positive assertion for whatever is supposed to happen when the bug is fixed.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!