As we see here in 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'});
}]);
routing test is suggested to be done with e2e test,
it('should redirect index.html to index.html#/phones', function() {
browser().navigateTo('../../app/index.html');
expect(browser().location().url()).toBe('/phones');
});
However, I think the '$routeProvider' config is done with a single function, function($routeProvider), and we should be able to unit test without involvement of browser since I think routing function does not require browser DOM.
For example,
when url is /foo, templateUrl must be /partials/foo.html and controller is FooCtrl
when url is /bar, templateUrl must be /partials/bar.html and controller is BarCtrl
It is a simple function IMO, and it should also be tested in a simple test, a unit test.
I googled and searched for this $routeProvider unit test, but no luck yet.
I think I may borrow some code from here but couldn't make it yet, https://github.com/angular/angular.js/blob/master/test/ng/routeSpec.js.
question from:
https://stackoverflow.com/questions/15990102/angularjs-route-unit-testing 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…