[英]Wait in Mocha api tests
我有以下用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);
});
你有等待的經驗嗎? 我如何正確地做到這一點?
您的代碼:
this.timeout(30000);
因此將等待30秒。
您可以使用:
this.timeout(360000); // '6m'
將超時增加到6分鍾(您可以將360000更改為其他值)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.