Angularjs 在指令上测试预编译函数

Angularjs 在指令上测试预编译函数,angularjs,Angularjs,如何在指令上对预编译函数进行单元测试?我可以在编译后检查作用域,但我想知道是否有更好的方法 angular.module('app') .directive('mailcheck', function () { return { compile: fu

如何在指令上对预编译函数进行单元测试?我可以在编译后检查作用域,但我想知道是否有更好的方法

angular.module('app')                                                        
  .directive('mailcheck', function () {                                                        
    return {
      compile: function() {
        return {                                                                               
          pre: function(scope, element, attributes, controller) {                              
            scope.mailcheck = controller;                                                      
          }
          post: ...
        }
      }
    };
  });
测试:

“严格使用”;
description('指令:mailcheck',函数(){
//加载指令的模块
每个模块之前(模块('8SecondsToTradeGuiApp');
var元素,
范围
beforeach(注入(函数($rootScope){
scope=$rootScope.$new();
元素=“”;
元素=$compile(元素)(范围);
范围。$digest();
}));    
});     
'use strict';

describe('Directive: mailcheck', function () {                                                 

  // load the directive's module
  beforeEach(module('8SecondsToTradeGuiApp'));                                                 

  var element,
    scope;

  beforeEach(inject(function ($rootScope) {                                                    
    scope = $rootScope.$new();

    element = '<input mailcheck>';                                                             
    element = $compile(element)(scope);
    scope.$digest();
  }));    
});