I am trying to stub the mongoose dependency used in this object:
var Page = function(db) {
var mongoose = db || require('mongoose');
if(!this instanceof Page) {
return new Page(db);
}
function save(params) {
var PageSchema = mongoose.model('Page');
var pageModel = new PageSchema({
...
});
pageModel.save();
}
Page.prototype.save = save;
}
module.exports = Page;
Using the answer for this question, I've tried doing this:
mongoose = require 'mongoose'
sinon.stub mongoose.Model, 'save'
But I got the error:
TypeError: Attempted to wrap undefined property save as function
I also tried this:
sinon.stub PageSchema.prototype, 'save'
And then I got the error:
TypeError: Should wrap property of object
Can anyone help with this? What am I doing wrong?