Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
When i run "node --inspect-brk node_modules/.bin/jest --runInBand" to debug my jest test the "const mongoose = require('mongoose')" returns a reference error. How to fix this ?
my test code is:
const {getDocuments} = require('./handleDatabase');
const mongoose = require('mongoose');
const userSchema = require('../schemas/user');
const UserModelTest = mongoose.model('userTest', userSchema);
test('Should return a array of documents', async() => {
debugger;
const dbConfig = require('../../bin/dbConfig');
await dbConfig(27017, 'test');
const query = {};
const documents = await getDocuments(query, UserModelTest);
expect(documents).toEqual(expect.not.objectContaining({status: false}));
My test runs very well, the unique problem that i found was the reference error when i try to import mongoose and my mongooseSchema.
full error msg:
"ReferenceError: mongoose is not defined
at eval (eval at Object..test (/home/sergipesecurity/Desktop/projetoBetBom/src/services/getDocuments.test.js:7:2), :1:1)
at Object..test (/home/sergipesecurity/Desktop/projetoBetBom/src/services/getDocuments.test.js:7:2)
at Object.asyncJestTest (/home/sergipesecurity/Desktop/projetoBetBom/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)
at resolve (/home/sergipesecurity/Desktop/projetoBetBom/node_modules/jest-jasmine2/build/queueRunner.js:43:12)
at new Promise ()
at mapper (/home/sergipesecurity/Desktop/projetoBetBom/node_modules/jest-jasmine2/build/queueRunner.js:26:19)
at promise.then (/home/sergipesecurity/Desktop/projetoBetBom/node_modules/jest-jasmine2/build/queueRunner.js:73:41)"
–
After makes more tests and put the debugger key in other places in my code, i saw this error in others variables. it should be a perfomance feature.
I put debugger key one line after const mongoose = require('mongoose')
and works.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.