我正在使用摩卡进行测试
it('should allow a POST to /users', async function () {
const res = await request.post('/users').send(firstUserBody);
expect(res.status).to.equal(201);
expect(res.body).not.to.be.empty;
expect(res.body).to.be.an('object');
expect(res.body.id).to.be.a('string');
firstUserIdTest = res.body.id;
});
Run Code Online (Sandbox Code Playgroud)
但我有一个错误
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Run Code Online (Sandbox Code Playgroud)
如果我使用 done() 执行此操作,该函数不是异步的,但它应该是
it('should allow a POST to /users', async function (done) {
const res = await request.post('/users').send(firstUserBody);
expect(res.status).to.equal(201);
expect(res.body).not.to.be.empty;
expect(res.body).to.be.an('object');
expect(res.body.id).to.be.a('string');
firstUserIdTest = res.body.id;
done();
});
Run Code Online (Sandbox Code Playgroud)
我应该怎么办 ?