我有以下用Mocha编写的api测试 我将插入内容放入数据库中,并在5分钟(缓存)后在api响应中提供了已编辑的值。
我应该如何在测试用例中等待缓存? 现在我使用以下代码,它给了我错误
Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\apiTests\test\07_0_dbtests.js)
我的功能:
it('should get updated restaurant calendar for dine in', function (done) {
this.timeout(30000);
setTimeout(function(){
tempUrl = `/rest/v1/restaurants/${config.restaurant_id_for_sql_queries}/DINE_IN`;
request
.get(tempUrl)
.set(config.headers)
.set('Authorization', `Bearer ${auth_token}`)
.end(function (err, res) {
logger.info(utils.logToConsole(res.request.url));
assert.equal(res.status, 200, 'response status!=200');
today = utils.getDayNameFromDate(utils.getTodayDate());
jsonstring = "";
switch (new Date().getDay()) {
case 0: assert.isTrue(res.body.details.channels.DINE_IN.openHoursSun.closeAllDay, 'restaurant should be closed all day'); break;
case 1: assert.isTrue(res.body.details.channels.DINE_IN.openHoursMon.closeAllDay, 'restaurant should be closed all day'); break;
case 2: assert.isTrue(res.body.details.channels.DINE_IN.openHoursTue.closeAllDay, 'restaurant should be closed all day'); break;
case 3: assert.isTrue(res.body.details.channels.DINE_IN.openHoursWed.closeAllDay, 'restaurant should be closed all day'); break;
case 4: assert.isTrue(res.body.details.channels.DINE_IN.openHoursThu.closeAllDay, 'restaurant should be closed all day'); break;
case 5: assert.isTrue(res.body.details.channels.DINE_IN.openHoursFri.closeAllDay, 'restaurant should be closed all day'); break;
case 6: assert.isTrue(res.body.details.channels.DINE_IN.openHoursSat.closeAllDay, 'restaurant should be closed all day'); break;
}
assert.isTrue(res.body.details.channels.DINE_IN.closeAllDay, 'restaurant should be closed all day');
done(err);
});
},30000);
});
您有等待的经验吗?我该怎么做呢?
答案 0 :(得分:1)
您的代码:
this.timeout(30000);
所以它将等待30秒。
您可以使用:
this.timeout(360000); // '6m'
将超时时间增加到6分钟(您可以将360000更改为其他值)。