使用Promise是更好的解决方案,而不是使用 mocha/chai 进行 API 测试超时?对于很多测试,我在下面遇到这样的错误,并希望防止这些错误。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')
});
});