使用 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.
可能緣由:測試時有鏈接數據庫,測試結束沒有關閉。async
解決辦法:mongoose
··· import * as mongoose from 'mongoose'; ··· describe('AppController (e2e)', () => { ··· afterAll(async () => { mongoose.disconnect(); }); })