How does one stub promise with sinon?

后端 未结 5 2157
耶瑟儿~
耶瑟儿~ 2020-12-13 01:55

I have a data service with following function

function getInsureds(searchCriteria) {

    var deferred = $q.defer();

    insuredsSearch.get(searchCriteria,
         


        
5条回答
  •  别那么骄傲
    2020-12-13 02:28

    You just have to resolve the promise before you call the search function. This way your stub will return a resolved promise and then will be called immediately. So instead of

    var resolveStub = sinon.stub(deferred, "resolve");
    

    you will resolve the deferred with your fake response data

    deferred.resolve({insureds: results103})
    

提交回复
热议问题