[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 ...
随机推荐
- sql - 面试
一,关于 group by 表内容: 2005-05-09 胜 2005-05-09 胜 2005-05-09 负 2005-05-09 负 2005-05-10 胜 2005-05-10 负 200 ...
- linux c下几种定时器实现
1.alarm n秒后触发一次,不是循环的2.setitimer 可以发出3种信号给自己,3.timerfd 这个接口基于文件描述符,通过文件描述符类似epoll那种的可读事件进行超时通知,能够被用于 ...
- C++函数覆盖的思考
最近碰到一些问题,一开始很难调试和解决,最后发现原来是在基类函数的模板方法中对子类需要重写的函数没有使用virtual,如下 class Base { public: void say(){test( ...
- Linux imagemagic(转载)
原文地址:http://linux.chinaitlab.com/c/803455.html 更多详细使用示例请参考:http://www.ibm.com/developerworks/cn/open ...
- python3可变与不可变数据类型
Python3中有六个标准的数据类型: Number(数字) String(字符串) List(列表) Dictionary(字典) Tuple(元组) Set(集合) 我理解的可变就是当一个变量创建 ...
- Scrapy使用以及Xpath的一些坑, 再入剁手
scrapy爬虫: https:www.scrapy.org 本篇博客依托的项目: https://github.com/viciousstar/BitcointalkSpider/ 一. Scrap ...
- jquery图片上传
总结两个图片上传的方法: 一:使用jquery.form中的ajaxSubmit来实现上传. <script src="~/JavaScript/jquery-1.10.2.min.j ...
- XCode7打包上传报错
在XCode7上传应用时,上传失败遇到两个错误,提示如下: ERROR ITMS-90535: "Unexpected CFBundleExecutable Key. The bundl ...
- solr拼写检查代码逻辑
自定义的solr搜索系统作为web应用发布到tomcat后,运行过程中其搜索代码逻辑如下: 用户solr搜索应用发送搜索请求URL,solr应用的org.apache.solr.servlet.Sol ...
- 转:MFC之COleVariant
COleVariant 本质上是一个枚举,用同一种类型来表达不同的子类型.如同boost中的variant. 例子 COleVariant var(3.6f); float v = var.fltVa ...