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