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);
}));
});