Stubbing the mongoose save method on a model

前端 未结 2 913
太阳男子
太阳男子 2020-12-17 18:58

I would like to stub the save method available to Mongoose models. Here\'s a sample model:

/* model.js */
var mongoose = require(\'mongoose\');
         


        
2条回答
  •  执笔经年
    2020-12-17 19:23

    Have you tried:

    sinon.stub(userModel.prototype, 'save')
    

    Also, where is the helper function getting called in the test? It looks like you define the function as the utils module, but call it as a method of a controller object. I'm assuming this has nothing to do with that error message, but it did make it harder to figure out when and where the stub was getting called.

提交回复
热议问题