Stubbing a Mongoose model using Sinon

前端 未结 3 583
故里飘歌
故里飘歌 2020-12-16 05:11

I am trying to stub the mongoose dependency used in this object:

var Page = function(db) {

    var mongoose = db || require(\'mongoose\');

    if(!this ins         


        
3条回答
  •  囚心锁ツ
    2020-12-16 06:05

    page = new Page();
    sinon.stub(page, 'save', function(cb){ cb(null) })
    

    Above code is deprecated.

    Please try to add fake function for your stub as below -

    sinon.stub(page, 'save').callsFake(function(cb){
          // do your Fake code
          cb(null)
    })
    

提交回复
热议问题