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

236
Visualizações
Testing truthy / falsy values with assert/expect

when I write tests I often use such constructions with assert

 try {
   await asyncFunction(); // expect error
   assert(false) // to make 100% fail
 } catch (err) {
   assert(err) // means 'assert(true) 
 }

Now I need to use "expect" from chai lib and I don't know how to write exactly the same test with 'expect' syntax

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You might try

expect.fail("This should've not happenned");

or another "more readable" alternative

should.fail("This should've not happenned");

Chai docs

In this section looks like there is a cool idiomatic way to perform what you want:

const action = function() { yourSyncFunction() }
expect(action).to.throw(YourError)

And here there's the DSL for testing promises. (You need to install the "As promised" plugin)

yourAsyncFunction().should.be.rejectedWith(Error)
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