0
테스트하기 전에 지시문을 설정해야하는 지시문에 대한 단원 테스트에 문제가 있습니다. BeforeEach with expectGets는 한 번 이상 실행될 수 없습니다.
이
내가 그것을 초기화 방법입니다 : 이var elm, $templateCache
var count = 0;
beforeEach(module('app/js/directives/templates/mytemplate.html'));
beforeEach(inject(function($injector) {
$templateCache = $injector.get('$templateCache');
}));
beforeEach(inject(
['$httpBackend','$compile','$rootScope', function(_$compile) {
var template = $templateCache.get('app/js/directives/templates/mytemplate.html');
if(count == 0){
$httpBackend.expectGET('js/directives/templates/mytemplate.html').respond(template);
}
elm = angular.element('<div my-directive</div>');
$compile(elm)($rootScope);
if(count == 0){
$httpBackend.expectGET('/app/js/content/some.json').respond('{ "left" : "<div>Contact information</div>"}');
$httpBackend.flush();
}
$rootScope.$digest();
count++;
}]
));
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
it("should work like I want it to", function() {
$rootScope.my-directive.somefunction();
expect($rootScope.somevalue).toBe(2);
});
it("should load the previous page if the function scope.layover.qa_pager.prev is called", function() {
$rootScope.my-directive.someotherfunction();
expect($rootScope.somevalue).toBe(1);
});
이 작동하지만 카운트 해킹은 내 의견으로는 필요하지 않을 것이다. 만약 내가 떠나면 $ httpbackend에 문제가 생기므로 매번 다시 초기화되지 않는 것 같아서 '오류 : 불만족스러운 요청 : GET /app/js/content/some.json'및 '오류 : 보류 중이 아닙니다. 플러시 요청! '
https://github.com/karma-runner/karma-ng-html2js-preprocessor
하지만, NG-html2js 우리 팀은 아직 사용할 수없는 새로운 카르마입니다, 나는 맹 글링 경로를해야합니까 .. – Maarten