2

Hello guys and thank you for your time.

I am testing with jest, using mongo memory server and mongoose schema. One of my tests require me to use mockingoose, however from the point that i import mockingoose (import mockingoose from 'mockingoose') every query that i do such as findOne directed to my mongo memory server will return the value of undefined.

code for example:

it('should work using mockingoose', () => {
       mockingoose(userModel).toReturn(userDoc, 'findOne');
       mockingoose(enterpriseMembersModel).toReturn([], 'aggregate');
       mockingoose.resetAll();
       //HERE i want to use mockingoose
}

it('should work using mongo memory server as usual', async () => {

       const user = await userModel.findOne({_id: '5d303198550375179d5bb156'});
       console.log(user);

       //Return undefined for user.
       //It will return an actual user only after removing mockingoose from the imports.
}

Is there any way to overcome this problem? Thanks in advance!

0 Answers0