[AngularJS + Unit Testing] Testing a component with requiring ngModel
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的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- [Angular Unit Testing] Testing Component methods
import {ComponentFixture, TestBed} from '@angular/core/testing'; import {BrowserDynamicTestingModule ...
- [Angular + Unit] AngularJS Unit testing using Karma
http://social.technet.microsoft.com/wiki/contents/articles/32300.angularjs-unit-testing-using-karma- ...
- [Unit Testing] Angular Test component with required
export default (ngModule) => { describe('Table Item component', () => { let $compile, directiv ...
- [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 ...
- 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 ...
随机推荐
- 绑定用户id,用户权限认证
上面这个就是为了把user_id与文章关联起来 文章需要跟用户关联,所以要去文章模型中加以关联 这样就可以直接在模板中进行关联处理 权限认证 首先要创建policy php artisan make: ...
- Python面向对象(约束,异常处理,md5加密)(五)
1. 类的约束 1. 写一个父类. 父类中的某个方法要抛出一个异常 NotImplementedError class Base: def login(self): raise NotImplemen ...
- Python包,json&pickle,time&datetime,random模块
补充内容: 解决模块循环导入的两种方法:(不得已而为之,表示程序结构不够严谨) 将导入模块语句放在文件最下方 保证语句导入之前函数内代码能够被执行 将导入语句放进函数体内 使其不影响整个函数的运行 包 ...
- timer event
/* linux/kernel/time/jiffies.c*/ static cycle_t jiffies_read(struct clocksource *cs) { return (cycle ...
- 利用visual studio 搜索替换功能清除项目中javascript文件的debugger;
在做web项目中,写js代码时候,会有一堆的debugger;,当时又懒得删,后面就多起来了,在vs的编辑器里面,其查找替换功能支持正则和整个项目/解决方案替换,这样就很容易删掉debugger;,方 ...
- Java-获取Class对象的名称
package com.tj; public class MyClass2 { public static void main(String[] args) { Class cls = java.la ...
- Windows phone UI虚拟化和数据虚拟化(一)
今天和大家分享一些关于windows phone ui虚拟化和数据虚拟化的一些知识. 也顺便回答我上一篇[LongListSelector 控件 在 wp7 和wp8中的不同之处]里,留下的那个问题, ...
- 解决Linux 服务器ntpdate同步时间报错 the NTP socket is in use, exiting
错误信息: 错误原因分析: 由于 xntpd 已经绑定到了该 Socket.运行 ntpdate 时,它会首先进行广播,然后侦听端口 123. 如果 xntpd 正在运行,而有一个进程已经在侦听该端口 ...
- 【Luogu】P2340奶牛会展
题目链接 突发奇想可以用f[i]表示智商和为i的时候情商最大是多少.这样就变成了一个背包问题. 最后更新答案的时候从0到最大背包容量遍历,最后答案是最大的i+f[i]; 但是虽然答案只能从0到m里选, ...
- java面试题之什么是死锁、活锁、饿死和竞态条件?
死锁:是指两个或两个以上的进程(或线程)在执行过程中,因争夺资源而造成的一种相互等待的现象,若无外力作用,他们将无法推进下去: 活锁:是指两个线程优先级相同,都礼让不走,就这样一直僵持下去: 饿死:在 ...