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