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. vue2.0的基本特性

    本文目前总结的特性如下1.侦听属性和计算属性2.class的绑定3.条件渲染时的注意事项4.v-if和v-for同时使用的注意事项5.插槽6.ref,父组件调用子组件的另一种方式7.<keep- ...

  2. DOM事件模型浅析

    1.何为DOM DOM是"Document Object Model"的缩写,中文译为"文档对象模型".它是一种跨平台.跨语言的编程接口,将HTML,XHTML ...

  3. Lex与Yacc学习(五)之正则表达式篇

    正则表达式语法 lex模式是由编辑程序和实用程序使用的正则表达式的扩展版本.正则表达式由常规字符(代表它们本身)和元字符(在一种模式中具有特殊含义)组成. 元字符 . . 匹配除了换行符 \n 之外的 ...

  4. 牛客网暑期ACM多校训练营(第四场)G Maximum Mode(思维)

    链接: https://www.nowcoder.com/login?callBack=%2Facm%2Fcontest%2F142%2FG 题意: 给定n个数, 要求删去恰好m个数后的最大总数是多少 ...

  5. 树形 dp

    // ACM训练联盟周赛     C. Teemo's tree problem There is an apple tree in Teemo's yard. It contains n nodes ...

  6. Beyond Compare 30天评估期结束解决办法

    打开Beyond Compare 4,提示已经超出30天试用期限制 解决方法: 1.修改文件 修改C:\Program Files\Beyond Compare 4\BCUnrar.dll ,这个文件 ...

  7. 关于php使用xpath解析html中文乱码问题

    $str2 = '<div id="content">我很好 </div>'; $dom = new DOMDocument(); //load之前强转字符 ...

  8. adb 命令大全

    传送门 --> https://github.com/mzlogin/awesome-adb ADB,即 Android Debug Bridge,它是 Android 开发/测试人员不可替代的 ...

  9. 【HTML/XML 1】HTML 速成总结

    导读:反反复复的看完了HTML的速成材料,前面学习了牛腩,所以这块知识只能是作为一种旧知识的复习.和机房重构时的SQLHelper一样,刚开始都是稀里糊涂的用了,后面系统的学习后,才知道为什么要那样用 ...

  10. java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment问题解决

    2018-09-29 17:45:16.905 ERROR [pool-1-thread-1]o.s.scheduling.support.TaskUtils$LoggingErrorHandler. ...