如何使用Jasmine JS对嵌套的Promise进行单元测试?

时间:2019-01-29 05:00:28

标签: unit-testing jasmine parse-server jasmine-node

我正在编写一些Parse服务器云功能,并试图了解如何编写涉及嵌套承诺的单元测试。例如

Parse.Cloud.define("myfunction", function(request){
   const common = require('./common')(Parse);

   return common.firstPromise
    .then(function(firstValue){
      return common.secondPromise(firstValue, request.parama.p1);
    })
   .then(function(secondValue){
      return common.thirdPromise(secondValue, request.param.p2);
    })
   .then(function(thirdValue){
       return Parse.run("anotherFunction",{thirdValue:thirdValue});
    })
    .catch(function(e){
       //log
       return Promise.reject(e)
    });
});

我正在使用类似于like this的设置。我有什么选择来确保每个嵌套的承诺调用都可以通过参数等调用/不调用。还是我需要重构并处理Promise链中的每个功能?

0 个答案:

没有答案
相关问题