摩卡-在执行测试之前等待一分钟



我遇到一种情况,测试需要等待一分钟才能执行。尝试了以下代码,但不起作用:

describe('/incidents/:incidentId/feedback', async function feedback() {
it('creates and update', async function updateIncident() {
// this works fine
});
// need to wait here for a minute before executing below test
it('check incident has no feedback', function checkFeedback(done){
setTimeout(function(){
const result = send({
user: 'Acme User',
url: `/incidents/${createdIncident.id}/feedback`,
method: 'get',
});
console.log(result);
expect(result.response.statusCode).to.equal(200);
expect(result.response.hasFeedback).to.equal(false);
done();
}, 1000*60*1);
});
});

这里,send()返回Promise。我试过用async await,但没用。

如何让测试在执行前等待一分钟

如果使用promise,它们最好不要与普通回调混合使用。

const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
...
it('check incident has no feedback', async function checkFeedback(){
this.timeout(1.33 * 60 * 1000);
await wait(1 * 60 * 1000);
const result = await send(...);
...
});

最新更新