Is using Promise a better solution instead of using timeout for API testing using mocha/chai? I am getting error like this below for lot of tests and want to prevent those errors. Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
describe('Email Tests', function() {
let messagingApiPath = '/v2/email';
let testData = require(`../../${testJsonFileName}`);
let positiveAssertions = function(response) {
console.log('Response : \n', response.text);
expect(response.statusCode).equals(200);
expect(response.status).equals(200);
expect(response.emailReferenceId == 36);
};
describe('POST /v2/email with TO and CC', function() {
console.log('Test Data File: ' + testJsonFileName);
describe('with To: CC: Test-Case-1', function() {
it('response with email id reference expected', function(done) {
request
.post(messagingApiPath)
.send(input)
.expect((response) => positiveAssertions(response))
.end(done);
});
});
//many more tests like describe('POST /v2/email')
});
});
Thanks for the comments that helped me get to an answer. For now (since I do not want to mock the response) editing the grunt configuration (increasing the time out) helped.