Home > Mobile >  Mongoose model function timed out when running inside jest testrunner
Mongoose model function timed out when running inside jest testrunner

Time:12-23

I am trying to add testing to the existing codeblock on my backend api using jest framework.

For the function create user

enter image description here

where insertUser is calling save function on db

enter image description here

I get the following test in test file

enter image description here

enter image description here

CodePudding user response:

so the reason it didn't work was because the mongoose.connect was never called inside the failing test file. Inside the other file was the existing logic for the database, requiring app in user.router.test.js fixed the problem.

alternatively doing the mongoose.connect inside the jest test file also works.

    beforeAll(async () => {
    const url = "mongodb://localhost/crm_ticket_system";
    await mongoose.connect(url);
  • Related