为什么在nodejs中测试我的代码时出现错误

时间:2018-12-14 21:03:43

标签: node.js unit-testing jestjs

我正在使用MongoDBNodeJsChai来测试代码。

连接到mongodb:

if (!!connection) {
    model = connection.model('client', clientSchema, collections.clients[env]);
} else {
    model = mongoose.model('client', clientSchema, collections.clients[env]);
}

这是单元测试:

describe('Bad VSA card test', () => {

    it('should contains VSA accounts', async (done) => {
        const vsaCard =  await updatedVSA();
        console.log(vsaCard);
        expect(vsaCard.length).to.equal(5);
        done();
    });

    afterAll(() => {
        client.disconnect();
    });

});

运行此测试代码时,出现错误:

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.

实际上,我首先搜索了此错误。我发现了类似的问题。通过关闭数据库连接修复了他的错误。为什么关闭MongoDB连接仍会出现此错误?

0 个答案:

没有答案