angularjs路由单元测试
发布时间:2020-12-17 08:50:36 所属栏目:安全 来源:网络整理
导读:正如我们在 http://docs.angularjs.org/tutorial/step_07看到的, angular.module('phonecat',[]). config(['$routeProvider',function($routeProvider) { $routeProvider. when('/phones',{templateUrl: 'partials/phone-list.html',controller: PhoneListC
正如我们在
http://docs.angularjs.org/tutorial/step_07看到的,
angular.module('phonecat',[]). config(['$routeProvider',function($routeProvider) { $routeProvider. when('/phones',{templateUrl: 'partials/phone-list.html',controller: PhoneListCtrl}). when('/phones/:phoneId',{templateUrl: 'partials/phone-detail.html',controller: PhoneDetailCtrl}). otherwise({redirectTo: '/phones'}); }]); 路由测试建议用e2e测试, it('should redirect index.html to index.html#/phones',function() { browser().navigateTo('../../app/index.html'); expect(browser().location().url()).toBe('/phones'); }); 然而,我认为’$ routeProvider’配置是完成与一个单一的函数,函数($ routeProvider),我们应该能够单位测试而不涉及浏览器,因为我认为路由功能不需要浏览器DOM。 例如, 它是一个简单的功能IMO,它也应该在一个简单的测试,一个单元测试。 我googled并搜索这个$ routeProvider单元测试,但没有运气。 我想我可以从这里借一些代码,但还不能做到,https://github.com/angular/angular.js/blob/master/test/ng/routeSpec.js。
为什么不只是断言路由对象配置正确?
it('should map routes to controllers',function() { module('phonecat'); inject(function($route) { expect($route.routes['/phones'].controller).toBe('PhoneListCtrl'); expect($route.routes['/phones'].templateUrl). toEqual('partials/phone-list.html'); expect($route.routes['/phones/:phoneId'].templateUrl). toEqual('partials/phone-detail.html'); expect($route.routes['/phones/:phoneId'].controller). toEqual('PhoneDetailCtrl'); // otherwise redirect to expect($route.routes[null].redirectTo).toEqual('/phones') }); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- Bootstrap typeahead不显示AJAX结果
- angular effects简明指南
- angularjs – 使用查询检索记录,AngularFire
- hp unix oracle rac节点一磁盘损坏,节点修复
- bash – 为什么`crontab -`删除crontab,它可以被
- Getting Started with AngularJS 1.5 and ES6: p
- 数组 – 为什么我的数组不适合我的shell脚本?
- npm – Angular 2找不到Promise,Map,Set和Iterat
- unix – 给定特定索引节点结构的最大文件大小?
- bash – 确定shell脚本是否已执行“源”
热点阅读