pgPromise如何在Jest单元测试完成时终止所有数据库连接

问题描述

在使用pgPromise库的Jest单元测试文件中,出现此错误

测试运行一秒钟后,Jest没有退出

我想这应该是因为我的app.ts中有以下代码

$ cat ${HOME}/.k3d/registries.yaml
mirrors:
  "registry.localhost:5000":
    endpoint:
      - "http://registry.localhost:5000"

});;

我在单元测试文件中使用了相同的导入。

db来自

import {db} from './shared/db';
...
let sco: any;
db.connect().then(function (obj: any) {
  sco = obj;
  obj.client.query('LISTEN "table_update"');
  obj.client.on('notification',function (data: any) {
      var result = JSON.parse(data.payload);
  log.info(result);
  globalEmitter.emit(
    eventTypes.Entity_Data_Changed,result
}
catch(error) {
  log.error({ error },'Error happened');
})
.finally(() => {
// release the connection,if it was successful:
 if (sco) {
    sco.done();
 }

在单元测试文件中,我的代码结尾

const db = pgp(options);

我试图pgp.end()杀死所有连接,因为我怀疑app.ts文件中的db表达式不属于连接池,因为我之前在某处读过它。但是仍然没有运气。任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)