The component test:

describe('The component test', () => {
let component, $componentController, $controller, $injector, $scope; beforeEach(module("componennts.module"));
beforeEach(inject((_$componentController_, _$controller_, _$injector_, _$rootScope_) => {
$componentController = _$componentController_;
$controller = _$controller_;
$injector = _$injector_;
$scope = _$rootScope_.$new();
})); describe('Controller', () => {
it('should have ng-model with the correct binding', () => {
let locals = {
$scope: $scope,
$element: angular.element('<my-component ng-model="value"></my-component>'),
$attrs: { ngModel: 'value' }
};
locals.$scope.value = [];
let ngModelController = $injector.get('ngModelDirective')[].controller;
let ngModelInstance = $controller(ngModelController, locals);
$scope.$digest();
component = $componentController('myComponent', null, { ngModel: ngModelInstance });
component.$onInit();
expect(component).toBeDefined();
expect(component._selectedValues).toEqual([]); // _selectedValues = ngModel.$viewValue
});
});
});

[AngularJS + Unit Testing] Testing a component with requiring ngModel的更多相关文章

  1. [AngularJS Unit tesint] Testing keyboard event

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

  2. [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 ...

  3. [Angular & Unit Testing] Testing a RouterOutlet component

    The way to test router componet needs a little bit setup, first we need to create a "router-stu ...

  4. [Angular & Unit Testing] Testing Component with Store

    When using Ngrx, we need to know how to test the component which has Router injected. Component: imp ...

  5. [Angular Unit Testing] Testing Component methods

    import {ComponentFixture, TestBed} from '@angular/core/testing'; import {BrowserDynamicTestingModule ...

  6. [Angular + Unit] AngularJS Unit testing using Karma

    http://social.technet.microsoft.com/wiki/contents/articles/32300.angularjs-unit-testing-using-karma- ...

  7. [Unit Testing] Angular Test component with required

    export default (ngModule) => { describe('Table Item component', () => { let $compile, directiv ...

  8. [AngularJS + Unit Testing] Testing Directive's controller with bindToController, controllerAs and isolate scope

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

  9. Run Unit API Testing Which Was Distributed To Multiple Test Agents

    Recently I am blocked by a very weird issue, from the VS installed machine, I can run performance te ...

随机推荐

  1. verdi知识点

    引用:http://blog.csdn.net/naclkcl9/article/details/5425936 1. verdi 加强了active anotation, active trace和 ...

  2. jQuery和Vue

    jQuery 概述 是js的一种函数库有美国人 John Resig编写 特点 写的少,做的多,国内用的jq1.0版本,可以兼容低版本的浏览器,支持链式编程或链式调用和隐式迭代 链式编程 $(this ...

  3. 爬虫必备:Python 执行 JS 代码 —— PyExecJS、PyV8、Js2Py

    在使用爬虫中,经常会遇到网页请求数据是经过 JS 处理的,特别是模拟登录时可能有加密请求.而目前绝大部分前端 JS 代码都是经过混淆的,可读性极低,想理解代码逻辑需要花费大量时间.这时不要着急使用 S ...

  4. 打印 Python 的一切 —— pprint & beeprint

    打印,是所有程序员从小白时期就具备的神技,遇事不决打印一下,是 DEBUG 最简单且不依赖 IDE 的方式,自定义各种日志输出,也是项目成型后必备功能.但是为了优雅的打印格式,往往需要对各种对象进行特 ...

  5. URI URL URN 关系

    我们一起来看下面这个虚构的例子.这是一个URI: http://bitpoetry.io/posts/hello.html#intro 我们开始分析 http:// 是定义如何访问资源的方式.另外 b ...

  6. Django中的app及mysql数据库篇(ORM操作)

    Django常见命令 在Django的使用过程中需要使用命令让Django进行一些操作,例如创建Django项目.启动Django程序.创建新的APP.数据库迁移等. 创建Django项目 一把我们都 ...

  7. visual studio 的生成、重新生成、清理功能的说明

    生成 生成当前选中的项目,依赖的项目如果已经生成dll,则不生成,直接拷贝过来 重新生成 生成当前选中的项目,依赖的项目也会生成 清理 清除掉生成的dll和相关文件

  8. c#笔记2018-12-26

    using System; /*C#学习笔记2018-12-26 * 1.@逐字字符串 * 2.数据类型转换 * 3.变量声明和占位符使用 * 4.接收用户输入值 * 5.const 关键字 * 6. ...

  9. mac 打开apach 但无法访问localhost的解决方法

    y由于mac系统默认自带了PHP和Apach, 所以可以通过 sudo apachectl start 直接启动apach服务, 此时在浏览器输入http://localhost,会出现It work ...

  10. lamp环境配置,ubunutu下

    Ubuntu下快速搭建LAMP环境过程记录: 安装 Apache2: sudo apt-get install apache2 安装PHP模块: sudo apt-get install php5 安 ...