小编Chi*_*eng的帖子

如何使用jasmine测试指令中的'ng-click'事件

我想用茉莉花测试角度'ng-click'事件,但我不知道怎么做

我的指令文件是这样的(headbarDirective.js):

 (function () {
        angular.module('app.widgets.homeHeadbar',[])
            .directive('homeHeadbar', homeHeadbar);

        function homeHeadbar() {
            return {
                restrict: 'EAC',
                replace: true,
                transclude: false,
                scope: {
                    name: '@',
                    role: '@',
                },
                templateUrl: 'app/widgets/headbar/headbarView.html',
                link: function(scope, ele, attrs) {
                    if (!scope.name) {
                        scope.logined = false;
                    } else {
                        scope.logined = true;
                    }
                    scope.logout = function() {
                        UserService.logout();
                        $location.path('/login');
                };
                }
            };
        }
    })();
Run Code Online (Sandbox Code Playgroud)

像我这样的模板文件(headbarView.html):

 <nav>
  <div>
    <div class="navbar-right" ng-show="logined">

      <div class="dib fr ml20">
         <div class="user-name cwh">{{name}}</div>
         <div class="user-position cgray">{{role}}</div>
      </div>

      <a class="logout" href="javascript:;" ng-click="logout()">Log Out</a>

    </div> …
Run Code Online (Sandbox Code Playgroud)

jasmine angularjs karma-jasmine

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

angularjs ×1

jasmine ×1

karma-jasmine ×1