Unit-test promise-based code in Angularjs

后端 未结 3 816
走了就别回头了
走了就别回头了 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

    And as yet another option you can avoid having to call $digestby using the Q library (https://github.com/kriskowal/q) as a drop-in replacement for $q e.g:

    beforeEach(function () {
        module('Module', function ($provide) {
            $provide.value('$q', Q); 
        });
    });
    

    This way promises can be resolved/rejected outside of the $digest cycle.

提交回复
热议问题