Jasmine Karme Unit test - AngularJs Directive is not getting compiled

[亡魂溺海] 提交于 2021-02-11 12:58:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!