[英]Jest “Cannot log after tests are done. Did you forget to wait for something async in your test?”
[英]Cannot log after tests are done problem in Express App in Jest tests
這是我的 Jest 測試
it('test the endpoint', async done => {
const request = supertest('http://localhost:3000/myexp');
request.get('/router1')
.expect(200)
.end((err, res) => {
if(err) {
throw err;
} else {
expect(res.text).toEqual('direct use 1st');
}
});
done();
})
測試運行成功,但它說測試完成后無法登錄。 由於我將 HTTP 請求發送到 Express App 路由器,並且它應該記錄一些消息,例如“API 收到了 [object Object] 的請求”。
在這種情況下如何記錄消息?
試試這個和 JSON.stringify(obj) 來查看你的對象
it('test the endpoint', async done => {
const request = supertest('http://localhost:3000/myexp');
request.get('/router1')
.expect(200)
.end((err, res) => {
if(err) {
throw err;
} else {
expect(res.text).toEqual('direct use 1st');
done();
}
});
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.