I am trying to add testing to the existing codeblock on my backend api using jest framework.
For the function create user
where insertUser is calling save function on db
I get the following test in test file
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);