angularjs route unit testing

前端 未结 3 836
Happy的楠姐
Happy的楠姐 2020-12-04 13:23

As we see here in http://docs.angularjs.org/tutorial/step_07,

angular.module(\'phonecat\', []).
  config([\'$routeProvider\', function($routeProvider) {
  $r         


        
3条回答
  •  甜味超标
    2020-12-04 13:59

    Why not just assert the route object is configured correctly?

    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')
      });
    });
    

提交回复
热议问题