0

I have some APIs which take more than 2 seconds. When I execute the test cases for these APIs I am getting the below error

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (xxxxx/dist/__tests__/acceptance/employee.controller.acceptance.js)
      at listOnTimeout (node:internal/timers:559:17)
      at processTimers (node:internal/timers:502:7)

I followed the answers in these thread How to increase timeout for a single test case in mocha. It helps me to increase the timeout of one test case as below. How can I configure the timeout for a group of test cases or for all test cases ?

describe('EmployeeController', () => {

  let app: ExpressServer;
  let client: Client;

  afterEach(async() => {
    
    clearDatabase();
    await app.stop();
    
  });

  beforeEach(async() => {

    ({app, client} = await setupApplication());

  });



  it('Create an employee - Fresh User', async() => {

    const token = await generateUserToken(client, 'user.1@5by.one');
    const resL = await client.get('/api/auth/users/my-account')
    .set({Authorization: `Bearer ${token}`}).send()
      .expect(200);
    const permissions = {
      ...accouontingPermissions,
      ...systemPermissions
    };
    await client.post('/api/auth/employees')
    .set({Authorization: `Bearer ${token}`}).send({
      name: 'Emp One',
      email: 'employee.1@5by.one',
      permissions,
      role: 'user',
    })
      .expect(200);
    
  }).timeout(5000);;

});
Prince Francis
  • 2,995
  • 1
  • 14
  • 22

0 Answers0