Unit testing 茉莉花-测试指令

Unit testing 茉莉花-测试指令,unit-testing,angularjs-directive,jasmine,Unit Testing,Angularjs Directive,Jasmine,我在做一个爱奥尼亚项目。以下指令从其所使用的元素中删除类 angular.module('employer') .directive('displayTab', function($timeout) { var css = angular.element('<style>').html( '.has-tabs{ bottom: 0; }\n' + '.no-tabs{ top: 44px; }'); document.body.appendChild(cs

我在做一个爱奥尼亚项目。以下指令从其所使用的元素中删除类

angular.module('employer')
.directive('displayTab', function($timeout) {

  var css = angular.element('<style>').html(
    '.has-tabs{ bottom: 0; }\n' +
    '.no-tabs{ top: 44px; }');

  document.body.appendChild(css[0]);
  return {
    restrict: 'A',
    compile: function(element, attr) {

      var bar = document.querySelector('.tab-nav');
      return function($scope, $element, $attr) {
        var navigate = $element[0].querySelector('.scroll-element');

        $scope.$on('$ionicView.beforeEnter', function() {
          bar.classList.remove('sliding');
          navigate.classList.remove('no-tabs');       
        })
      }
    }
  };
});
如何正确测试此指令

describe('directive', function() {
         var $rootScope, $compile, $scope;
         var el, markup, scrolling, bar;
         var markup = '<div display-tab></div>';

         beforeEach(function() {
                    module('employer');

                    inject(function($injector) {
                           $rootScope = $injector.get('$rootScope');
                           $compile = $injector.get('$compile');

                           $scope    = $rootScope.$new();

                           el   = $compile(angular.element(markup))($scope);

                           });
                    });

         $body.append(el);
         $rootScope.$digest;

         describe('bar directive', function() {
                  it('should assign a class to the element', function() {
                     scope.$emit('$ionicView.beforeEnter');
                     scope.$digest();

                   });
         });