Reputation: 3097
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, '[email protected]');
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: '[email protected]',
permissions,
role: 'user',
})
.expect(200);
}).timeout(5000);;
});
Upvotes: 0
Views: 182
Reputation: 1
you can add the following in .mocharc.json file
{ "recursive": true, "require": "source-map-support/register", "timeout": 5000 }
Upvotes: 0