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

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

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 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