[AngularJS + Unit Testing] Testing Directive's controller with bindToController, controllerAs and isolate scope
- <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的更多相关文章
- AngularJS入门心得1——directive和controller如何通信
粗略地翻了一遍<JavaScript DOM编程艺术>,就以为可以接过AngularJS的一招半式,一个星期过去了,我发现自己还是Too Young,Too Simple!(刚打照面的时候 ...
- [AngularJS Unit tesint] Testing keyboard event
HTML: <div ng-focus="vm.onFocus(month)", aria-focus="{{vm.focus == month}}", ...
- [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 ...
- [AngularJS + Unit Testing] Testing a component with requiring ngModel
The component test: describe('The component test', () => { let component, $componentController, $ ...
- angularJS中directive与controller之间的通信
当我们在angularJS中自定义了directive之后需要和controller进行通讯的时候,是怎么样进行通讯呢? 这里介绍3种angular自定义directive与controller通信的 ...
- 我也谈 AngularJS 怎么使用Directive, Service, Controller
原文地址:http://sunqianxiang.github.io/angularjs-zen-yao-shi-yong-directiveservicecontroller.html 其转自大漠穷 ...
- AngularJS:何时应该使用Directive、Controller、Service?
AngularJS:何时应该使用Directive.Controller.Service? (这篇文章你们一定要看,尤其初学的人,好吗亲?) 大漠穷秋 译 AngularJS是一款非常强大的前端MVC ...
- AngularJS自定义Directive与controller的交互
有时候,自定义的Directive中需要调用controller中的方法,即Directive与controller有一定的耦合度. 比如有如下的一个controller: app.controlle ...
- angularjs可交互的directive
angularjs可交互的directive http://jsfiddle.net/revolunet/s4gm6/ directive开发上手练手,以注释的方式说明 html <body n ...
随机推荐
- 关于js的callback回调函数的理解
回调函数的处理逻辑理解:所谓的回调函数处理逻辑,其实就是先将回调函数的代码 冻结(或者理解为闲置),接着将这个回调函数的代码放到回调函数管理器的队列里面. 待回调函数被触发调用的时候,对应的回调函数的 ...
- 一次 php nusoap 调试过程
今天跟同事调用一个数据api ,用soap方式调用.本以为很简单的事情,却弄到了晚上. 因为有过调试经验,直接按照以往的过程直接部署,结果是错误. 1. 以为是调用方式错了,问了一下对接的同事,没问题 ...
- 修改虚拟机linux硬盘的大小
一.概述 Ubuntu用了一段时间,系统已从原来的4G增长到8G,导致虚拟磁盘不够用,需要修改虚拟硬盘的大小. 但是,修改虚拟机硬盘的大小不像修改内存那么简单,操作一个滑动条就轻松搞定.要知道虚拟硬盘 ...
- mysql update from 子查询
mssql 子查询更新 update log set uin= b.uinfrom log a,logs bwhere a.accountuin = b.accountuin mysql 不支持 up ...
- iOS:处理XML文件
NSXMLParser是标准库类 Book.xml <?xml version="1.0" encoding="UTF-8"?> <!--Do ...
- 关于.NET的配置文件
无论是exe文件还是dll文件,都可以添加App.config文件,里面设置配置信息.比如<appSettings></appSettings>之间,可以加入Key-Value ...
- 【关于JavaScript】常见表单用户名、密码不能为空
在论坛等系统的用户注册功能中,如果用户忘记填写必填信息,如用户名.密码等,浏览器会弹出警告框,提示用户当前有未填信息. 这个典型的应用就是通过JavaScript实现的.如图所示是一个简单的用户注册页 ...
- [BZOJ 1559] [JSOI2009] 密码 【AC自动机DP】
题目链接:BZOJ - 1559 题目分析 将给定的串建成AC自动机,然后在AC自动机上状压DP. 转移边就是Father -> Son 或 Now -> Fail. f[i][j][k] ...
- Java 字节码
Java作为业界应用最为广泛的语言之一,深得众多软件厂商和开发者的推崇,更是被包括Oracle在内的众多JCP成员积极地推动发展.但是对于Java语言的深度理解和运用,毕竟是很少会有人涉及的话题.In ...
- C语言中.h和.c文件解析
整理自C语言中.h和.c文件解析(很精彩) Part.1(林锐<高质量C/C++编程>) 通过头文件来调用库功能.在很多场合,源代码不便(或不准)向用户公布,只要向用户提供头文件和二进制的 ...