2017-01-17 8 views
1

Jasmineは非同期関数が期待通りに実行されるのを待つようにしますか?非同期呼び出しのジャスミンユニットテスト待ち

コントローラでscope.init()をテストします。この関数は、3非同期私は私の期待するのを実行する前に移入するdropdown1、dropdown2、dropdown3を待つことができますどのようにこの1

$scope.init = function() { 

    //populate parameterList 

    myService.getDropdowns(parameterList).then(function(response) { 
     if (response && response.data) { 
      $scope.dropdown1 = response.data; 
     } 

    }, function(errorResponse) { 
     $log.error(errorResponse); 
    }); 

    //populate parameterList 

    myService.getDropdowns(parameterList).then(function(response) { 
     if (response && response.data) { 
      $scope.dropdown2 = response.data; 
     } 

    }, function(errorResponse) { 
     $log.error(errorResponse); 
    }); 

}; 

に似呼び出す含まれていますか?私は各ドロップダウンが正常に入力されたことをテストしようとしています。

答えて

0

あなたはこのようにそれを行うことができます。

describe('your test', function(){ 

    beforeEach(function(done){ 
     // You can call any async task, when done() is called the test will begin 
     setTimeout(() => {done();}, 100); 
    }); 

    it('Column Definitions created', function(){ 
     expect($scope.a).toBe(3); 
    }); 
}); 
関連する問題