How does one stub promise with sinon?

后端 未结 5 2162
耶瑟儿~
耶瑟儿~ 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:12

    At current sinon version v2.3.1, you can use stub.resolves(value) and stub.rejects(value) function

    For example, you can stub myClass.myFunction with following code

    sinon.stub(myClass, 'myFunction').resolves('the value you want to return');
    

    or

    sinon.stub(myClass, 'myFunction').rejects('the error information you want to return');
    

提交回复
热议问题