2017-03-14 13 views
0

私は働きたいと思っているいくつかの壊れたテストを継承しました。ジャスミンでAngular 1.5を使用しています。 「実際」のコントローラーでは、次のようになります。

function myfunction() { 
    $scope.stop = function() { 
    $interval.cancel(promise); 
    $timeout.cancel(timeout); 
    }; 
    ......... 

この関数は、コントローラーの上部で呼び出されます。私のテストファイル内

私が使用して間隔とタイムアウトを設定します

私のテストが実行時点で
'use strict'; 

var $scope; 
var $timeout; 


describe('Pas', function(){ 
describe('PasController', function() { 
    var $this; 
    var $rootscope; 
    var PasService; 
    var $interval = jasmine.createSpy('$interval', $interval).and.callThrough(); 
    var $timeout = jasmine.createSpy('$timeout', $timeout).and.callThrough(); 

    beforeEach(module('CL.Pas')); 

    beforeEach(inject(function (_$controller_, _$rootScope_, _PasService_, _$interval_, _$timeout_) { 
     $rootscope = _$rootScope_; 
     PasService = _PasService_; 
     $interval = _$interval_; 
     $timeout = _$timeout_; 

     var data = { 
      "Id": "00000000-0000-0000-0000-000000000000", 
      "SectionSlug": "string", 
      "SectionName": "PAS", 
      "Sections": [ 
       { 
        id: "00000000-0000-0000-0000-000000000001", 
        Mandatory: true, 
        description: "test 1", 
        name: "Section 1", 
        status: "Not Started" 
       }, 
       { 
        id: "00000000-0000-0000-0000-000000000003", 
        Mandatory: false, 
        description: "test 3", 
        name: "Section 3", 
        status: "Started" 
       }, 
       { 
        id: "00000000-0000-0000-0000-000000000002", 
        Mandatory: true, 
        description: "test 2", 
        name: "Section 2", 
        status: "Not Started" 
       } 
      ], 
      Forms: [] 
     }; 

     spyOn(PasService, 'canSubmitMandatorySections').and.callFake(getFakePromise({Result: false})); 
     spyOn(PasService, 'canSubmitOptionalSections').and.callFake(getFakePromise({Result: false})); 
     spyOn($interval, 'cancel'); 
     spyOn($timeout, 'cancel'); 


     $this = _$controller_('PasController', {sections: data, PasService: PasService, canSubmitIndividual: true, $scope: $scope, $timeout : $timeout, $interval: $interval}); 
    })); 

    it('should split available sections', function() { 
     $rootscope.$apply(); 

     expect($this.sections.mandatory.length).toEqual(2); 
     expect($this.sections.optional.length).toEqual(1); 
    }); 
}); 
}); 

私はTypeError例外を受け取る:未定義のプロパティ「停止」を設定することはできません。私はテストでこれを偽造しますか? $コントローラ

+0

をインスタンス化するのを忘れて、あなたは全体のテストをしてください投稿することができますか?またはjsbinなどへのリンクを提供しますか?その「停止」はあなたが書いたもの($ scope.stop)を参照しているようには見えません。 – rrd

+0

@rrd私はテスト全体を表示するために質問を変更しました – bilpor

答えて

0

から$これを設定しようとすると、セットアップで

それ誤差は私がスコープ$scope = $rootscope.$new();

関連する問題