Jasmine Karme 单元测试 - AngularJs 指令未编译

Jasmine Karme Unit test - AngularJs Directive is not getting compiled

我在测试 angularjs 指令时遇到问题。以下是我的测试:

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);
    }));

console.log 的输出为

'<div class="ng-scope"><some-directive-name></some-directive-name></div>'

相反,它应该是 someDirectiveName 指令

的模板 URL

指令:

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) {
   ......
   ......

实际上我没有遇到任何异常。但我发现了问题。我没有将 js 指令文件的引用添加到业力配置中。这是一个愚蠢的错误