Many questions have been raised about the ng-html2js plugin, but unfortunately, none of the answers provided were able to solve my specific issue.
I meticulously followed the official installation guide and also referenced the example available at https://github.com/vojtajina/ng-directive-testing/blob/master/test/tabsSpec.js.
My objective is to test a directive that includes a templateUrl property, as outlined in my configuration below.
karma.conf.js
files: [
... // various other files included here
'app/views/**/*.html' // all templates stored here
],
[...] // additional karma configurations listed here
preprocessors: {
'app/views/**/*.html': ['ng-html2js']
},
The directive I am aiming to test is quite straightforward:
'use strict';
angular.module('myAwesomeApp').directive('rzMenu', function () {
return {
templateUrl: 'views/directives/rzmenu.html',
restrict: 'E'
};
});
Below is the unit test file for this directive:
'use strict';
describe('Directive: rzmenu', function () {
// load the module containing the directive
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('');
}));
});
In the 'should have content' test mentioned above, shouldn't the content match the template? Why is an empty string being returned instead?
Any insights or assistance would be greatly appreciated. Thank you.