Using Sinon to stub chained Mongoose calls

前端 未结 5 1501
感情败类
感情败类 2020-12-31 10:34

I get how to stub Mongoose models (thanks to Stubbing a Mongoose model with Sinon), but I don\'t quite understand how to stub calls like:

myModel.findOne({\"         


        
5条回答
  •  抹茶落季
    2020-12-31 11:00

    If you use Promise, you can try sinon-as-promised:

    sinon.stub(Mongoose.Model, 'findOne').returns({
      exec: sinon.stub().rejects(new Error('pants'))
      //exec: sinon.stub(). resolves(yourExepctedValue)
    });
    

提交回复
热议问题