1
수 시간 동안 검색하고 실험 한 후 내 마음이 날아갔습니다. AngularJS 제공자를 단위 테스트하는 방법에 대한 직접적이고 실제적인 예는 어디에도 없습니다. 아무리 노력해도 문제가 해결되지 않습니다.AngularJS : 제공자를 단위 테스트하는 방법
아래 예에서 서비스가 제대로 주입되고 작동합니다. 공급자는 구성이 가능해야하는 코드 블록에 도착하지 않기 때문에 삽입 할 수 없으며 구성 할 수 없습니다.
'AngularJS 제공자를 단위 테스트하는 방법'을 제공 할 수있는 사람이 있습니까?
angular.module('app',[]);
angular.module('app').service('testBasicService', function() {
return {
serviceMethod: function() {
alert("serviceMethod");
}
};
});
angular.module('app').provider('testAdvancedService', function() {
this.$get = function() {
this.providerMethod = function() {
alert("providerMethod");
}
}
});
describe("Test", function() {
beforeEach(module("app"), function (testAdvancedServiceProvider) {
// code never arrives here
});
it("should just work", inject(function (testBasicService, testAdvancedService) {
testBasicService.serviceMethod();
testAdvancedService.providerMethod(); // testAdvancedService is undefined here
}));
});
반환이 속임수를 썼는지 : 당신이 기능을 테스트 할 공급자에 정의되어있는 경우
, 나는이 작품 것을 발견했다. $ provide.provider 호출이 필요하지 않은 것 같습니다. 이것없이 모든 작품. 감사 ! –