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

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

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