简体   繁体   中英

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. 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:

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. If I remove mongoose from the test it runs fine.

The problem appears to have been with my jest.config.js file. I had moduleDirectories: ["node_modules", "src"], set. When I commented this line out I no longer had the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM