Zeeshan Noor Zeeshan Noor - 3 months ago 25x
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') );