2017-10-24 3 views
0

In this plunkサービス機能を模擬しようとする角度/ジャスミンテストがあります。サービス関数mockedは、サービス内の別の関数によって呼び出される必要があります。模擬ジャスミンスローズ法の角度サービスが見つかりません

これは私が取得エラーです:

Error: getTheDate() method does not exist 

そして、これは、関数がgetTheMonthをテストした私の試みですが、嘲笑機能getTheDateを呼び出す必要があり、spyOnが誤って使用されているようです:

angular.module("mymodule", []) 

.service('myService', function(){ 

    this.getTheDate = function() { 
     return new Date(); 
    }; 


    this.getTheMonth = function() { 
     var d = this.getTheDate(); 
     return d.getMonth(); 
    }; 
}) 

describe("Testing date functions", function() { 

    beforeEach(function(myService) { 
     module("mymodule"); 
     var d = new Date(); 
     d.setDate(12) 
     d.setMonth(2); 
     d.setFullYear(2018); 
     spyOn(myService, 'getTheDate').and.returnValue(d); 
    }); 


    it('should return the month', 

     inject(function(myService) { 

     expect(myService.getTheMonth()).toEqual(2); 


    })); 

}); 

答えて

1
beforeEach(function(myService) { 
    module("mymodule"); 

Updated plunkr

関連する問題