ng-html2js プラグインについては多くの質問がありますが、残念ながらすべての回答が y の問題を解決するのに役立ちませんでした。
公式のインストール ガイドと例https://github.com/vojtajina/ng-directive-testing/blob/master/test/tabsSpec.jsに従いました。
私の目標は、templateUrl プロパティを持つディレクティブをテストすることです。これは私の構成です
カルマ.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('');
}));
});
「コンテンツが必要」テストを見てください。テンプレートと同じコンテンツであってはなりませんか?
なぜ私は空の文字列を取得するのですか?
前もって感謝します