[英]Testing with mongoose and typescript: RangeError: Maximum call stack size exceeded - node_modules/mongodb/src/bson.ts:38:3
I'm running tests with jest on a node/express application.我在 node/express 应用程序上用 jest 运行测试。 Anytime that I run anything with mongoose I get the following error:
每当我用猫鼬运行任何东西时,我都会收到以下错误:
● 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)
When I've read other stackoverflow posts on this it tends to be an issue of iterating over multiple documents, but I still get an issue when I'm considering a single document:当我阅读有关此的其他 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);
});
The fact that my console.log doesn't run at all makes me thing there's something wrong with mongoose/typescript.我的 console.log 根本没有运行的事实让我觉得 mongoose/typescript 有问题。 If I remove mongoose from the test it runs fine.
如果我从测试中删除猫鼬,它运行良好。
The problem appears to have been with my jest.config.js
file.问题似乎与我的
jest.config.js
文件有关。 I had moduleDirectories: ["node_modules", "src"],
set.我有
moduleDirectories: ["node_modules", "src"],
设置。 When I commented this line out I no longer had the problem.当我评论这条线时,我不再遇到问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.