How does one stub promise with sinon?

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

    There's one more alternative I found. Much pain free than other methods.

    You can use this npm package: sinon-stub-promise.

    It abstracts much of the details, so that you don't have to invent the wheel again. Helped my write my tests after struggling to simulate a promise for long.

    Hope it helps!

提交回复
热议问题