2014-09-08 4 views
2

ng-html2js 플러그인에 관해 많은 질문이 있지만 불행히도 모든 대답이 y 문제를 해결하는 데 도움이되지 않았습니다.ng-html2js를 사용한 AngularJS 지시문

나는 공식 설치 가이드와 예제 https://github.com/vojtajina/ng-directive-testing/blob/master/test/tabsSpec.js을 따랐다.

내 목표는 templateUrl 속성이 지시문을 테스트하는 것입니다,이 내 설정

karma.conf.js

files: [ 
    ... // lots of studd here 

    'app/views/**/*.html' // templates are all here 
], 

[...] // other karma configs here 

preprocessors: { 
    'app/views/**/*.html': ['ng-html2js'] 
}, 

나는 그것을 테스트하고자하는 지시어 정말 기본입니다

'use strict'; 

angular.module('myAwesomeApp').directive('rzMenu', function() { 
    return { 
     templateUrl: 'views/directives/rzmenu.html', 
     restrict: 'E' 
    }; 
}); 

'use strict'; 

describe('Directive: rzmenu', function() { 

    // load the directive's module 
    beforeEach(module('myAwesomeApp')); 
    beforeEach(module('app/views/directives/rzmenu.html')); 

    var element, 
    scope; 

    beforeEach(inject(function ($rootScope, $compile) { 
    element = angular.element('<rzmenu></rzmenu>'); 
    scope = $rootScope.$new(); 
    element = $compile(element)(scope); 
    scope.$digest(); 
    })); 

    it('should have content', inject(function() { 
    //scope.$digest(); 
    var content = element.text(); 
    expect(content).toBe(''); 
    })); 
}); 
의 단위 테스트 파일

'내용이 있어야 함'테스트를보고 템플릿과 동일한 내용으로해서는 안됩니까?

왜 내가 빈 문자열을 얻나요? 그래서

stripPrefix: 'app/' 

뿐만 아니라 구성에 필요했다

1) cacheIds가 templateUrl 속성과 일치해야합니다 : 사전에

덕분에

답변

4

신경 끄시 고, 내가 해결이 오류 있었다 테스트 내에서 app/prefix없이 모듈을 호출하십시오.

beforeEach(module('views/directives/rzmenu.html')); 

2) 지침 이름은 인스턴스 호출이 보인다 테스트하기 위해 두통을 많이 해결하기 위해 가정 뭔가를 여기에 올바른

element = angular.element('<rz-menu></rz-menu>'); 

:

+3

이하, 잘못 그래서 낙타 표기법입니다 그냥 설정하는 많은 원인! 정보 주셔서 감사합니다 – Katana24