【发布时间】:2020-03-06 01:13:23
【问题描述】:
当我运行一个笑话测试时,当我需要池时创建一个池实例,它返回一个 _pg.Pool is not a constructor 错误。
我试过查看 StackOverflow:pg.Pool is not a constructor
这仍然不起作用。
但是,当我运行代码时,我能够创建一个池实例,该错误仅在 Jest 中显示。
节点代码:
import { Pool } from 'pg'
const pool = new Pool({configs})
export default pool
错误日志:
● Test suite failed to run
TypeError: _pg.Pool is not a constructor
> 6 | const pool = new Pool({
|
at Object.<anonymous> (src/resources/connection.js:6:14)
at Object.require (src/routes/api.js:2:20)
at Object.<anonymous> (src/__tests__/integration/user.test.js:8:1)
旁注:代码是https://node-postgres.com/api/pool中文档的副本
我不希望发生错误,因为 pg.Pool 是一个带有构造函数的类。
【问题讨论】:
-
我也有同样的问题。你有没有解决它,@L。阿尔斯?
-
@heniotierra 我当时没有设法修复它,我不再处理该代码,但感谢您的帮助!
标签: node.js jestjs node-postgres