Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!