You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jest Mongo并发测试报错:TypeError: Cannot read 'getConnectionString' of undefined

Jest多测试文件运行时Mongo测试报错:TypeError: Cannot read property 'getConnectionString' of undefined

我碰到了一个疑似Jest的Bug,目前正在跟进相关问题的进展。我严格按照Jest官方文档配置并运行Mongo相关测试,但当同时运行多个测试文件时,触发了如下错误:

TypeError: Cannot read property 'getConnectionString' of undefined

错误发生在自定义Mongo环境类的setup方法中,具体代码位置如下:

3 | class MongoEnvironment extends NodeEnvironment {
4 |   async setup () {
>5 |     this.global.__MONGO_URI__ = await global.__MONGOD__.getConnectionString()
6 |     this.global.__MONGO_DB_NAME__ = global.__MONGO_DB_NAME__
7 |
8 |     await super.setup()

内容的提问来源于stack exchange,提问作者cyberwombat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:38:31