【发布时间】:2014-01-24 00:50:56
【问题描述】:
angularjs 中典型的 app.js 文件如下所示:
var phonecatApp = angular.module('phonecatApp', [
'ngRoute',
'phonecatControllers'
]);
phonecatApp.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'
});
}]); // the example is taken from the angularjs tutorial
您将如何对该文件进行单元测试?
这有点前卫和百分比覆盖率。首先测试它是否有意义? 我认为是的,因为当导航到某个 url 时,我想确保使用正确的路线。
注意:问题不仅在于测试 $routeProvider,还在于 app.config()。
谢谢!
【问题讨论】:
-
这个问题回答了我的想法。我有同样的问题,但将其重新表述为“测试 routeChange 事件”stackoverflow.com/questions/19093010/…
标签: angularjs angularjs-routing