Jest did not exit one second after the test run has completed.

使用 Jest 进行单元测试时出现如下问题:

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

可能原因:测试时有连接数据库,测试结束没有关闭。

解决办法:

···
import * as mongoose from 'mongoose';
···

describe('AppController (e2e)', () => {
     ···
    afterAll(async () => {
        mongoose.disconnect();
    });
})
posted @ 2019-10-31 15:05  啤酒煮鸡蛋  阅读(2366)  评论(0编辑  收藏  举报