[Unit Testing] Angular Unit Testing, ui-router, httpbackend and spy
// backend test beforeEach(inject(function (_$compile_, _$httpBackend_, _$rootScope_, _$state_, _AnnouncementsService_, _CONFIG_) {
compile = _$compile_;
$httpBackend = _$httpBackend_;
$scope = _$rootScope_.$new(); AnnouncementsService = _AnnouncementsService_;
CONFIG = _CONFIG_; // Need to mock $state, so the ui-router resolve wont conflict with tests.
state = _$state_;
spyOn( state, 'go');
spyOn( state, 'transitionTo'); directiveElem = getCompiledElement();
directiveCtrl = directiveElem.controller('comAnnouncements');
})); afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
}); it('should respond 200 to a http get request and get 1 announcement', function(){
AnnouncementsService.getAnnouncementData(2); let expectedResponse = [
{
"id": 0,
"title": "Maintenance work may affect Internet services 20/09/2015",
"date": "11 Nov 2015 | 12:30 PM"
}
]; $httpBackend.expectGET(CONFIG.BACKEND_API_URL + '/announcements/2').respond(200, { 'announcements': expectedResponse });
$httpBackend.flush();
expect(AnnouncementsService.announcementData).toEqual(expectedResponse);
}); // ui-router test it('Should move to "home state"', () => {
$scope.$apply(() => {
angular.element(directiveElem.find('a')[0]).click();
$timeout.flush();
}); expect($state.current.name).toEqual('selfcare.home');
}); it('$state href should equal "/home"', () => {
$scope.$apply(() => {
$state.go('selfcare.home');
});
expect($state.current.name).toEqual('selfcare.home');
expect($state.href('selfcare.home')).toEqual('/home');
}); // Click to expect function to be called it('should call goToSearch()', function(){
spyOn(directiveCtrl, 'goToSearch');
angular.element(directiveElem.find('.header-icon-menu i')[0]).click();
expect(directiveCtrl.goToSearch).toHaveBeenCalled();
});
[Unit Testing] Angular Unit Testing, ui-router, httpbackend and spy的更多相关文章
- angular : $location & $state(UI router)的关系
次序:angular 的 location会先跑 $rootScope.$on("$locationChangeStart", function (scope, newUrl, o ...
- 【原创】ui.router源码解析
Angular系列文章之angular路由 路由(route),几乎所有的MVC(VM)框架都应该具有的特性,因为它是前端构建单页面应用(SPA)必不可少的组成部分. 那么,对于angular而言,它 ...
- angularjs ngRoute和ui.router对比
ngRoute模块是angularjs自带的路由模块,ui.router是一个第三方路由模块,接下来将对两者进行一个对比: ng-router(angular-router.js) ng-view n ...
- ngRoute 与ui.router区别
angular路由 路由 (route) ,几乎所有的 MVC(VM) 框架都应该具有的特性,因为它是前端构建单页面应用 (SPA) 必不可少的组成部分. 那么,对于 angular 而言,它自然也有 ...
- ngRoute 和 ui.router 的使用方法和区别
在单页面应用中要把各个分散的视图给组织起来是通过路由机制来实现的.本文主要对 AngularJS 原生的 ngRoute 路由模块和第三方路由模块 ui.router 的用法进行简单介绍,并做一个对比 ...
- [Angular + Unit Testing] Mock HTTP Requests made with Angular’s HttpClient in Unit Tests
In a proper unit test we want to isolate external dependencies as much as possible to guarantee a re ...
- [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] Automatic change detection
When you testing Component rendering, you often needs to call: fixture.detectChanges(); For example: ...
- [Angular Unit Testing] Debug unit testing -- component rendering
If sometime you want to log out the comonent html to see whether the html render correctly, you can ...
随机推荐
- HTTP协议是什么?(及get和post请求的区别)
http://blog.csdn.net/xiemk2005/article/details/6108618 http://blog.csdn.net/mengleigaocong/article/d ...
- 统计机器翻译(SMT)步骤总结
本文是在Niutrans论坛中的系列教程中总结出来的. 1.语料预处理 预处理的结果是生成双语分词之后的文件,该步需要注意的是对规则短语,比如数字.日期.网址等,进行泛化处理.可以用正则方法或者其它方 ...
- Java学习----你可以告诉对象该怎么做(方法中传参)
对象根据参数传递来的条件执行相应的功能. package org.demo.app2; public class App2 { public void print(String msg, int nu ...
- ajax+XMLHttpRequest里的FormData实现图片异步上传
发这篇博客的时候我是自己在研究这个XMLHttpRequest请求,在别人的博客上面知道XMLHttpRequest新加了一个FormData的东西,好像现在APP请求后台也有用这种方式的吧. 别的不 ...
- oracle通过query导出指定条件的数据
通过下面的方式oracle可以导出指定了条件的数据: exp mixcoaldb/mixcoaldb@server tables=(shengcssjk) query=\"where to_ ...
- oracle常用SQL总结
这里我们介绍的是 40+ 个非常有用的 Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询.这些是所有 Oracle 开发者都必备的技能,所以快快收 ...
- CentOS 5.6服务器配置YUM安装Apache+php+Mysql+phpmyadmin
1. 更新系统内核到最新. [root@linuxfei ~]#yum -y update 系统更新后,如果yum安装时提示错误信息,请执行以下命令修复. [root@linuxfei ~]#rpm ...
- IOS学习:常用第三方库(GDataXMLNode:xml解析库)
IOS学习:常用第三方库(GDataXMLNode:xml解析库) 解析 XML 通常有两种方式,DOM 和 SAX: DOM解析XML时,读入整个XML文档并构建一个驻留内存的树结构(节点树),通过 ...
- Qt:截图工具,任意大小矩形截图、全屏截图
http://blog.csdn.net/rl529014/article/details/53146440
- Android 手机上安装并运行 Ubuntu 12.04(转,没实测)
设备需要root权限,并且安装了BusyBox最小 1GHz 处理器(推荐)Android 系统版本 2.1 或以上Android 设备需要自定义的ROM固件SD卡至2.5GB (安装大映像的需要3. ...