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

316
Views
Mocha Unit Test Timeout of 10000ms exceeded Error when using await Promise.all

File: index.ts // Class Based Default exported

getItemsA() {
  return Promise.resolve({ // Api Call in real scenario. Mocking here for now.
    success: true;
    result: [{
     itemA: []
    }]
  });
}

getItemsB() {
  return Promise.resolve({ // Api Call in real scenario. Mocking here for now.
    success: true;
    result: [{
     itemB: []
    }]
  });
}

File service.ts

import { getItemsA, getItemsB } from 'index.ts';

getService() {
  return new Promise(async (resolve, reject) => {
    const parallelApis = await Promise.all([  // UT Stucks here. Not able to get the parallelApis response.
      getItemsA(), getItemsB()
    ]);

   .... other mapping

   resolve({
      .......
   });
  });
}

File test.ts

import items from 'index.ts'; // Class based. Default exported
import service from 'service.ts'; // Class based. Default exported
import { expect } from "chai";
import * as sinon from "sinon";

describe.only("Service", () => {
   let itemAStub;
   let itemBStub;

   beforeEach(() => {
     itemAStub = sinon.stub(items, "getItemsA");
     itemBStub = sinon.stub(items, "getItemsB");

     itemAStub.callsFake(() => {
        return Promise.resolve({
            body: myMock // Dummy
        });
     });

   itemBStub.callsFake(() => {
        return Promise.resolve({
            body: someOtherMock // Dummy
        });
     });
   });

   afterEach(() => {
        itemAStub.restore();
        itemBStub.restore();
   });

   it("Should filter valid gift options", (done) => {
      service.getService().then(res => {
                console.log("RESPONSEEEEEE", res);
                expect(res).to.deep.equal(myMockResponse);
                done();
            })
            .catch(err => {
                console.log("Errorr");
                done(err);
            });
   });
});

Can somebody help me to identify the issue when i tried to run the test case I am getting the below error.

Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

I know that extending the timeout is not a solution to fix the issue. Stub is created, but not sure why it is getting timeout error when code reaches await Promise.all. If I remove done() then test case will succeed but then function is not getting executed. Any help would be really appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When we run Mocha from the command line, it will read this file which has a default timeout.

To change this time you can reset using:

./node_modules/.bin/mocha  --timeout 20000
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!