测试猫鼬和typescript: RangeError:最大调用堆栈大小超过- node_modules/mongodb



我正在一个节点/express应用程序上运行jest测试。每当我用mongoose运行任何东西时,我都会得到以下错误:

● Test suite failed to run
RangeError: Maximum call stack size exceeded
at Object.get [as ObjectId] (node_modules/mongodb/src/bson.ts:38:3)
at Object.get [as ObjectId] (node_modules/mongodb/src/bson.ts:38:3)
(... line repeats total of 10 times)

当我读过其他关于这个的stackoverflow帖子时,它往往是一个迭代多个文档的问题,但当我考虑单个文档时,我仍然会遇到一个问题:

test("mongoose works", async () => {
console.log("this does not log") // Nothing logs and I get the "test suite failed to run" error
const findResponse = await UserAction.findOne({
action: "testString1",
}).exec();
expect(findResponse).toBe(false);
});

我的console.log根本不运行的事实让我觉得mongoose/typescript有问题。如果我从测试中删除mongoose,它会运行良好。

问题似乎与我的jest.config.js文件有关。我有moduleDirectories: ["node_modules", "src"],集。当我把这行注释掉后,我就不再有这个问题了。

最新更新