Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

282
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda