Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda