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

306
Vistas
Mocha passing test when i expect throw, but muy function is not throwing

I have a function that I expect to throw an error, but if it doesn't throw it mocha passes the test.

async function throwError() {
   throw new Error("foo");
}
async function notThrowError() {
   
}

Test:

describe("bar", function(){
  it("bar-2", async function() {
     await expect(throwError()).throw //passes the test
})
}

describe("bar", function(){
  it("bar-2", async function() {
     await expect(notThrowError()).throw //passes the test, but no error has been thrown 
})
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I should use chai as promised

const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
chai.should();

describe("bar", function(){
   it("bar-2", async function() {
      return notThrowError().should.eventually.rejected; //do not pass the test if not throw an 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