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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM