Zeeshan Noor Zeeshan Noor - 1 year ago 146
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 Source

This is how i stubbed the functionality

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download