Zeeshan Noor Zeeshan Noor - 6 months ago 40
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 ?


This is how i stubbed the functionality

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