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

mocha - wait for a minute before executing test

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

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()returnsPromise。我试过 async await 但没用。

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

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

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(...);
    ...
  });