[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 ...
随机推荐
- CXF自动生成客户端
官网下载apache-cxf-3.1.6,bin目录下.配置环境变量,生成客户端 http://blog.csdn.net/jaune161/article/details/25499939 http ...
- extjs之TypeError: d.read is not a function解决方案
在创建如下代码时报出此错:TypeError: d.read is not a function Ext.define('shebyxgl_sheb_model', { extend: 'Ext.da ...
- HTML cellpadding与cellspacing属性
单元格(cell) -- 表格的内容 单元格边距(表格填充)(cellpadding) -- 代表单元格外面的一个距离,用于隔开单元格与单元格空间 单元格间距(表格间距)(cellspacing) - ...
- JS 单击复制,复制后变为已复制
这段代码是在新浪网站上找到的.先放出CSS代码: .focus a.arrow,.card_con4 li i,.cm1_menu_wrap a.cm1_menu_box,.cm1_img span, ...
- 转:Java开发牛人十大必备网站
原文来自于:http://www.importnew.com/7980.html 以下是我收集的Java开发牛人必备的网站.这些网站可以提供信息,以及一些很棒的讲座, 还能解答一般问题.面试问题等.质 ...
- PKUSC2016滚粗记
Day0 坐飞机来北京,地铁上接到电话,以为是诈骗电话马上就挂了,然后看了一下是北京的电话,赶脚有点不对...打回去居然是报到处老师的电话..走了几个小时,到勺园和其他学校的神犇合住.TAT,感觉第二 ...
- C51指针类型和存储区的关系详解
一.存储类型与存储区关系 data ---> 可寻址片内ram bdata ---> 可位寻址的片内ram idata ---> 可寻址片内ram ...
- java Future 模式
考慮這樣一個情況,使用者可能快速翻頁瀏覽文件中,而圖片檔案很大,如此在瀏覽到有圖片的頁數時,就會導致圖片的載入,因而造成使用者瀏覽文件時會有停頓 的現象,所以我們希望在文件開啟之後,仍有一個背景作業持 ...
- 14.1.1 使用InnoDB 表的好处:
14.1.1 Benefits of Using InnoDB Tables 14.1.2 Best Practices for InnoDB Tables 14.1.3 Checking InnoD ...
- 【HDOJ】1561 The more, The Better
树状DP. /* 1561 */ #include <iostream> #include <cstdio> #include <cstring> #include ...