[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 ...
随机推荐
- SVN global ignore pattern for c#
*.resharperoptions Web_Data log */[Bb]in [Bb]in */obj obj */TestResults TestResults *.svclog Debug ...
- Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view...
Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tabl ...
- Sql Server使用技巧
1.修改表的字段时,提示不能更改: 工具>选项>设计器>取消 阻止保存要求重新创建表的更改 2.更改选择多少行,编辑多少行: 工具>选项>Sql Server对象资源管理 ...
- delphi服务程序(service)的调试方法
方法一: 1.调试delphi 写的服务程序,有这么一个办法.原来每次都是用attach to process方法,很麻烦.并且按照服务线程的执行线路,可能会停不到想要的断点.笨办法是,在proced ...
- JSON带来编程界怎样的描述
JSON是一套数据对象组织格式,从程序员的角度观看,他是以种非常易读易写的形式来描述一种key-value的数据组织.全名称JavaScript Object Notation,从名称上可看已经说明他 ...
- 『重构--改善既有代码的设计』读书笔记----Inline Temp
与Inline Method相同,有时候犹豫需要Extract Method,需要对一些临时变量进行内联,而这个往往是Replace Temp with Query的一部分.简单来说,当你看到这种 d ...
- php 5.2 版本isset()方法小坑
PHP 5.2.17p1 (cli) (built: May 28 2015 16:15:30)Copyright (c) 1997-2010 The PHP GroupZend Engine v2. ...
- Python报错:SyntaxError: Non-ASCII character '\xe5' in file的解决方法
SyntaxError: Non-ASCII character '\xe5' in file 原因:Python默认是以ASCII作为编码方式的,如果在自己的Python源码中包含了中文(或者其他的 ...
- SCJP_104——题目分析(5)
18. public class Test { public static void add3(Integer i) { int val=i.intvalue(); val+=3; i=new Int ...
- ServiceStack.OrmLite
ServiceStack.OrmLite 谈谈我的入门级实体框架Loogn.OrmLite 每次看到有新的ORM的时候,我总会留意一下,因为自己也写过一个这样的框架,人总是有比较之心的.我可能会d ...