单元测试 – 我们可以为AngularJS routeProvider写单元测试吗?
发布时间:2020-12-17 08:08:17 所属栏目:安全 来源:网络整理
导读:嗨,我正在使用AngularJS构建一个应用程序,我被困在单元测试部分。我知道如何为控制器编写单元测试,但我不知道如何为routeProvider做它。我正在使用茉莉花写单元测试。 我的路由提供商将看起来像这样; var app = angular.module('MyApp',['ngResource']) a
嗨,我正在使用AngularJS构建一个应用程序,我被困在单元测试部分。我知道如何为控制器编写单元测试,但我不知道如何为routeProvider做它。我正在使用茉莉花写单元测试。
我的路由提供商将看起来像这样; var app = angular.module('MyApp',['ngResource']) app.config(function ($routeProvider) { $routeProvider .when('/',{ templateUrl: 'app/views/main.html',controller: 'MainCtrl' }) .when('/home/:PartyID',{ templateUrl: 'app/views/home.html',controller: 'HomeCtrl' }) .when('/edit/:PartyID',{ templateUrl: 'app/views/update_profile.html',controller: 'EditCtrl' }) .when('/route',{ templateUrl: 'app/views/route.html',controller: 'RouteCtrl' }) .when('/signup',{ templateUrl: 'app/views/signup.html',controller: 'SignupCtrl' }) .when('/login',{ templateUrl: 'app/views/login.html',controller: 'LoginCtrl' }) .otherwise({ redirectTo: '/' }); }); 如何使用Jasmine为此routeProvider写入单元测试?
是的,你可以,快速的答案,下面是一小段代码,可以使用和扩展,以测试路线带你到你想要的地方。
describe('Testing routes',function() { beforeEach(module('windscreens')); var location,route,rootScope; beforeEach(inject( function( _$location_,_$route_,_$rootScope_ ) { location = _$location_; route = _$route_; rootScope = _$rootScope_; })); describe('Login route',function() { beforeEach(inject( function($httpBackend) { $httpBackend.expectGET('login') .respond(200); })); it('should load the login page on successful load of /login',function() { location.path('/login'); rootScope.$digest(); expect(route.current.controller).toBe('LoginCtrl') }); }); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 复制包含在不同父文件夹中的许多文件(同名)
- Building a Recipe Search Site with Angular and Elastics
- shell – 如何通过替换文件名中的单词来重命名多个文件?
- webService xfire FAQ
- unix – 使用wget从谷歌学者搜索结果下载所有pdf文件
- scala – 在所有工作人员上拥有静态对象的正确方法是什么?
- scala – 无法使用Slick-play解析符号(foreach,list,…)
- shell判断文件目录或文件是否存在
- 在Angularjs中的jQuery ajax beforeSend相当于什么?
- 在Angular应用启动前获取数据并注入到应用中