<div>
<h2>{{vm.userInfo.number}} - {{vm.userInfo.name}}</h2>
</div>
'use strict';

class CardTitleInformCtrl {

    constructor() {

    }
} function CardTitleInformDirective() {
return {
restrict: 'EA',
scope: {},
bindToController: {
userInfo: '='
},
replace: true,
template: require('./card-title-inform.html'),
controller: CardTitleInformCtrl,
controllerAs: 'vm'
};
} export default (ngModule) => {
ngModule.directive('comCardTitleInform', CardTitleInformDirective);
};

Test:

export default (ngModule) => {
describe('card title inform test', () => { var $scope, $compile, html, directiveName, directiveElm, controller;
html = '<com-card-title-inform userInfo="userInfo"></com-card-title-inform>',
directiveName = 'comCardTitleInform'; beforeEach(window.module(ngModule.name));
beforeEach(inject(function(_$compile_, _$rootScope_){
$scope = _$rootScope_.$new();
$compile = _$compile_; directiveElm = $compile(angular.element(html))($scope);
controller = directiveElm.controller(directiveName);
$scope.$digest();
})); it('should has an h2 element with text 888-888-888 - Wan', function () { // Assign the data to the controller -- Because we use bindToController
controller.userInfo = {
name: "Wan",
number: "888-888-888"
};
// ControllerAs as 'vm', assign controller to the $scope.vm
$scope.vm = controller;
// Make it work
$scope.$digest(); expect(directiveElm.find('h2').text()).toEqual(controller.userInfo.number + ' - ' +controller.userInfo.name);
});
});
};

[AngularJS + Unit Testing] Testing Directive's controller with bindToController, controllerAs and isolate scope的更多相关文章

  1. AngularJS入门心得1——directive和controller如何通信

    粗略地翻了一遍<JavaScript DOM编程艺术>,就以为可以接过AngularJS的一招半式,一个星期过去了,我发现自己还是Too Young,Too Simple!(刚打照面的时候 ...

  2. [AngularJS Unit tesint] Testing keyboard event

    HTML: <div ng-focus="vm.onFocus(month)", aria-focus="{{vm.focus == month}}", ...

  3. [Unit Testing] AngularJS Unit Testing - Karma

    Install Karam: npm install -g karma npm install -g karma-cli Init Karam: karma init First test: 1. A ...

  4. [AngularJS + Unit Testing] Testing a component with requiring ngModel

    The component test: describe('The component test', () => { let component, $componentController, $ ...

  5. angularJS中directive与controller之间的通信

    当我们在angularJS中自定义了directive之后需要和controller进行通讯的时候,是怎么样进行通讯呢? 这里介绍3种angular自定义directive与controller通信的 ...

  6. 我也谈 AngularJS 怎么使用Directive, Service, Controller

    原文地址:http://sunqianxiang.github.io/angularjs-zen-yao-shi-yong-directiveservicecontroller.html 其转自大漠穷 ...

  7. AngularJS:何时应该使用Directive、Controller、Service?

    AngularJS:何时应该使用Directive.Controller.Service? (这篇文章你们一定要看,尤其初学的人,好吗亲?) 大漠穷秋 译 AngularJS是一款非常强大的前端MVC ...

  8. AngularJS自定义Directive与controller的交互

    有时候,自定义的Directive中需要调用controller中的方法,即Directive与controller有一定的耦合度. 比如有如下的一个controller: app.controlle ...

  9. angularjs可交互的directive

    angularjs可交互的directive http://jsfiddle.net/revolunet/s4gm6/ directive开发上手练手,以注释的方式说明 html <body n ...

随机推荐

  1. 博客系统-3.0CodeIgniter系统SAE版本的配置 application/config/

    autoload.php(系统启动时自动加载的文件:包,类库,驱动,方法助手,配置) $autoload['libraries'] = array('database', 'access', 'pag ...

  2. Jquery 和 Js

     jQuery  [一]  jQuery     1: javaScript和 javaScript库:        (1) javaScript自身存在的3个弊端:复杂的文档对象模型(DOM),不 ...

  3. compser 执行命令提示do not run composer as root/super !

    这个是因为composer为了防止非法脚本在root下执行,解决办法随便切换到非root用户即可

  4. PHP文件上传与安全

    文件上传的流程 上传必须由POST方式的file类型表单提交,被提交的地方 一定是一个php程序,用户在表单使用file类型的域.选在一个自己电脑上的文件,提交到php程序以后 其实就已经完成了一个上 ...

  5. MFC笔记

    一.Win32基本程序概念 所有的windows程序都必须载入windows.h MFC程序都有一个Stdafx.h文件,它载入了MFC框架必须的文件. Windows程序以消息为基础,以事件驱动之. ...

  6. python关键字

    python有多少关键字? >>> import keyword >>> keyword.kwlist ['and', 'as', 'assert', 'break ...

  7. bzoj 2331: [SCOI2011]地板 插头DP

    2331: [SCOI2011]地板 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 541  Solved: 239[Submit][Status] D ...

  8. delphi 连接 c++ builder 生成obj文件

    delphi 连接 c++ builder 生成obj文件 delphi 可以连接c++ builder 生成OMF格式的obj文件,会报一个错.[DCC Error] E2065 Unsatisfi ...

  9. Android 自定义dialog(AlertDialog的修改样式)

    LayoutInflater inflater = LayoutInflater(AudioActivity.this); View timepickerview = inflater.inflate ...

  10. VMware Workstation 不可恢复错误: (vcpu-0)