У меня есть следующий тест API, написанный в Мокко
Я помещаю вставки в базу данных, и отредактированные значения доступны в ответе API через 5 минут (кеш).
Как мне ждать кеша в моих тестовых случаях?
Теперь я использую следующий код, и он дает мне ошибку
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);
});
Есть ли у вас опыт ожидания? Как я могу сделать это правильно?