问题
I am having issues testing angularjs directive. Following is my test:
it('should be defined', inject(function($compile,$rootScope){
$scope = $rootScope.$new();
element = $compile('<div><some-directive-name></some-directive-name></div>')($scope);
$scope.$digest();
console.log(element[0].outerHTML);
expect(element.html()).toBe(template);
}));
Output for the console.log comes as
'<div class="ng-scope"><some-directive-name></some-directive-name></div>'
Instead it should be the template URL of someDirectiveName directive
Directive:
angular.module('app.moduleName').directive('someDirectiveName', function (someService) {
return {
restrict: 'EA',
replace: true,
templateUrl: 'app/path/partials/some-directive-name.tpl.html',
scope: true,
link: function (scope, element) {
......
......
回答1:
Actually I was not getting any exception. But I found the issue. I didn't added reference of the js directive file to karma config. Its a stupid mistake
来源:https://stackoverflow.com/questions/63585684/jasmine-karme-unit-test-angularjs-directive-is-not-getting-compiled