关于 ng-html2js 插件有很多问题,但不幸的是,所有答案都没有帮助我解决问题。
我遵循了官方安装指南和示例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('');
}));
});
看'should have content'测试,内容不应该和模板一样吗?
为什么我得到空字符串?
提前致谢