Zeeshan Noor Zeeshan Noor - 4 months ago 35
Node.js Question

Mocking mongoose

I have a mongoose model in a helper file, how can i stub the model and utilize find,update functionality

var mongoose = require('mongoose');
User = mongoose.model('User')
User.findById(userId).exec().then(function (boardExist) {});


So how can i mock/stub find,update functionality ?

Answer

This is how i stubbed the functionality

sinon.stub(User, 'findById') .returns(Promise.resolve('ReturnExpectedObject') );

Comments