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