[Unit Testing] Angular Test component with required
export default (ngModule) => {
describe('Table Item component', () => {
let $compile, directiveElem, directiveCtrl, $scope, state, parentElement;
beforeEach(window.module(ngModule.name));
beforeEach(inject(function (_$compile_, _$rootScope_, _$state_) {
$compile = _$compile_;
$scope = _$rootScope_.$new();
state = _$state_;
spyOn(state, 'go');
spyOn(state, 'transitionTo');
directiveElem = getCompiledElement();
directiveCtrl = directiveElem.controller('ttmdTableItem');
}));
it('should have the controller defined', () => {
expect(directiveCtrl).toBeDefined();
});
it('should have the parent controller defined', () => {
expect(directiveCtrl.listCtrl).toBeDefined();
});
it('should include desktop item', () => {
expect(directiveElem.find('ttmd-desktop-item').length).toEqual();
});
it('should include mobile item', () => {
console.log(parentElement);
directiveElem = getCompiledElement(true);
directiveCtrl = directiveElem.controller('ttmdTableItem');
$scope.$digest();
expect(directiveElem.find('ttmd-mobile-item').length).toEqual();
});
function getCompiledElement(b) {
$scope.item = {
"serviceCode": "1-655-834-8324",
"username": "Johann Homenick",
"amount": "4.37",
"dueDate": "2016-06-07T07:15:02.720Z"
};
$scope.headers = [
'id',
'number',
'username',
'amount',
'due date'
];
const
mockParentController = {
goMobile() {
return b || false;
}
};
parentElement = angular.element('<div><ttmd-table-item item="item" headers="headers"><ttmd-actions></ttmd-table-item></div>');
parentElement.data('$ttmdTableController', mockParentController);
const compiledDirective = $compile(parentElement)($scope)
.find('ttmd-table-item');
$scope.$digest();
return compiledDirective;
}
});
};
------------------------
Child:
class TtmdTableItemController {
constructor(ttMdTable) {
this.ttMdTable = ttMdTable;
}
getSelectedItem(){
return this.item;
}
}
const ttmdTableItemComponent = {
bindings: {
item: '=',
headers: '<',
hasTransclude: '<'
},
transclude: true,
replace: true,
require: {
'listCtrl': '^ttmdTable'
},
controller: TtmdTableItemController,
controllerAs: 'vm',
template: require('./table-item.html')
};
export default (ngModule) => {
ngModule.component('ttmdTableItem', ttmdTableItemComponent);
}
parent:
class TtmdTableController {
constructor(PaginationModel, $transclude) {
....
}
goMobile() {
return this.model.goMobile();
}
}
const ttmdTableComponent = {
bindings: {
...
},
transclude: {
'actions': '?ttmdActions'
},
controller: TtmdTableController,
controllerAs: 'vm',
template: require('./ttmd-table.html')
};
export default (ngModule) => {
ngModule.component('ttmdTable', ttmdTableComponent);
}
[Unit Testing] Angular Test component with required的更多相关文章
- [Unit Testing] Angular Unit Testing, ui-router, httpbackend and spy
// backend test beforeEach(inject(function (_$compile_, _$httpBackend_, _$rootScope_, _$state_, _Ann ...
- [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 methods
import {ComponentFixture, TestBed} from '@angular/core/testing'; import {BrowserDynamicTestingModule ...
- Unit Testing of Spring MVC Controllers: Configuration
Original Link: http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-m ...
- [Java Basics3] XML, Unit testing
What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...
- [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 ...
- C/C++ unit testing tools (39 found)---reference
http://www.opensourcetesting.org/unit_c.php API Sanity AutoTest Description: An automatic generator ...
- Unit Testing a zend-mvc application
Unit Testing a zend-mvc application A solid unit test suite is essential for ongoing development in ...
- TestApe - Unit testing for embedded software
TestApe - Unit testing for embedded software About this site Welcome - This site is TestApe.com. Mos ...
随机推荐
- android-'Using 1.7 requires compiling with Android 4.4 (KitKat); currently using API 8'
解决的方案是将jdk1.7制定的版本定制为jdk.6.即 在eclipse中,右键项目->Properties->Java Compiler->enable "projec ...
- iOS真机测试种可能遇到的问题
1. Reason- image not found 用模拟器是没有问题的,不过在真机好像是有问题,不确定是否是所有机型. 崩溃日志 1 2 3 4 5 dyld: Library not l ...
- Django 1.10中文文档—第一个Django应用Part1
在本教程中,我们将引导您完成一个投票应用程序的创建,它包含下面两部分: 一个可以进行投票和查看结果的公开站点: 一个可以进行增删改查的后台admin管理界面: 我们假设你已经安装了Django.您可以 ...
- JavaScript--垃圾回收器
垃圾回收: 释放不再被任何变量引用的对象 垃圾回收器: 专门记录对象的引用次数,并回收不再被引用的对象的程序. 垃圾回收器和主程序并行在后台执行 垃圾回收器会为每个对象创建一个引用计数器(counte ...
- 重新开始学习javase_集合_List
一,List之ArrayList(转:http://blog.csdn.net/zheng0518/article/details/42198205) 1. ArrayList概述: ArrayLis ...
- Shell 脚本编程笔记(一) Hello Shell
最近不断在接触Linux操作系统,对它一个终端走天下的特性感到十分新奇和伟大.同时也被各种命令折磨的死去活来...公司的一个老同事给我讲,在公司的极品geek宅都是只用一个黑黑的框完成一切的.结果我一 ...
- 页面d初始化加载
1.$(document).ready(function () { alert("Hello Word!"); }); 或简写为 2.$(function(){ alert(&qu ...
- apache静态文件配置
开发环境配置 需要下面几个步骤 1. 在app目录下创建static目录,将静态文件和相关文件夹放到此目录下,如your_app/static/img等 2. 确保settings.py中的INSTA ...
- jquery ajax用例样板
$.ajax({ url: '${managerPath}/customer/updateOrder.do', type: 'POST', async: false, data: { id: date ...
- openssl 进行证书格式的转换
各类证书由于存储的内容不同(如是否包含公钥/私钥是否加密存储/单一证书或多证书等).采用编码不同(DER/BASE64).标准不同(如PEM/PKCS),所以尽管X.509标准规定了证书内容规范,但证 ...