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. Cookies和Session的区别和理解

    Cookies和Session的区别和理解 cookie机制 Cookies是服务器在本地机器上存储的小段文本并随每一个请求发送至同一个服务器.IETF RFC 2965 HTTP State Man ...

  2. 异步FIFO最小深度计算

    计算FIFO深度是设计FIFO中常遇到的问题.常识告诉我们,当读速率慢于写速率时,FIFO便可被用作系统中的缓冲元件或队列.因此FIFO的大小基本上暗示了所需缓存数据的容量,该容量取决于读写数据的速率 ...

  3. 力扣题目汇总(反转字符串中的单词,EXCEL表列序号,旋置矩阵)

    反转字符串中的单词 III 1.题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode ...

  4. gg mirror

    https://gufen.ga/ (无广告,原guso.ml,ggso.ga,guge.ga) https://a.aiguso.tk (无广告,体验良好) https://a.freedo.gq/ ...

  5. go 和make的用法 区别

    Doand Make are two verbs which frequently confuse students of English. Learn the Difference between ...

  6. python3--__radd__处理右侧加法

    __radd__处理右侧加法 从严格意义上来讲,前边例子中出现的__add__方法并不支持+运算符右侧使用实例对象.要实现这类表达式,而支持可互换的运算符,可以一并编写__radd__方法.+右侧的对 ...

  7. 多线程下,多次操作数据库报错,There is already an open DataReader associated with this Command which must be closed first.

    原文:https://www.cnblogs.com/sdusrz/p/4433108.html 执行SqlDataReader.Read之后,如果还想用另一个SqlCommand执行Insert或者 ...

  8. Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)

    昨晚打得小号,虽然很菜,可是还是涨了些rating A. Arpa and a research in Mexican wave time limit per test 1 second memory ...

  9. iOS大转盘抽奖

    功能 点击大转盘旋转后固定到某个自己可以确定的位置 结构 转盘,开始按钮,指针 技术 CADisplayLink不停重绘,CGAffineTransform旋转,简单数学公式 核心代码 1.使用CAD ...

  10. 暑假训练Round1——G: Hkhv的水题之二(字符串的最小表示)

    Problem 1057: Hkhv的水题之二 Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format: ...