Unit-test promise-based code in Angularjs

后端 未结 3 821
走了就别回头了
走了就别回头了 2020-11-28 04:19

I\'m having hard times trying to test promise-based code in Angularjs.

I have the following code in my controller:

    $scope.markAsDone = function(t         


        
3条回答
  •  无人及你
    2020-11-28 04:50

    Another approach would be the following, taken straight out of a controller I was testing:

    var create_mock_promise_resolves = function (data) {
        return { then: function (resolve) { return resolve(data); };
    };
    
    var create_mock_promise_rejects = function (data) {
        return { then: function (resolve, reject) { if (typeof reject === 'function') { return resolve(data); } };
    };
    
    var create_noop_promise = function (data) {
        return { then: function () { return this; } };
    };
    

提交回复
热议问题