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

115
Views
Why is my test case passes but the assertion actually failed in mocha

My test case below passes but my Assertion failed. Why is it passing? I already have async in place and the updateSpy is not even called which is confirmed by my Assertion failed message. I also tried Done with promises.

it('should call the update  method once', async () => {
        const updateSpy = sinon.spy(() => 'Spy!');
    
        sinon.stub(service, 'db').resolves({
          collection(collectionName) {
            return {
              update: updateSpy,

                  };
          },
        });

       console.assert(updateSpy.called); // assertion failed but the test case was passed
  }); 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

From the ASSERTIONS doc:

Mocha allows you to use any assertion library you wish. In the above example, we’re using Node.js’ built-in assert module — but generally, if it throws an Error, it will work!

But console.assert() method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens. It will NOT throw an Error if the assertion is false.

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!