|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -describe('$route', function() { |
| 3 | +fdescribe('$route', function() { |
4 | 4 | var $httpBackend,
|
5 | 5 | element;
|
6 | 6 |
|
@@ -900,6 +900,87 @@ describe('$route', function() {
|
900 | 900 | });
|
901 | 901 |
|
902 | 902 |
|
| 903 | + it('should not get affected by modifying the route definition object after route registration', |
| 904 | + function() { |
| 905 | + module(function($routeProvider) { |
| 906 | + var rdo = {}; |
| 907 | + |
| 908 | + rdo.templateUrl = 'foo.html'; |
| 909 | + $routeProvider.when('/foo', rdo); |
| 910 | + |
| 911 | + rdo.templateUrl = 'bar.html'; |
| 912 | + $routeProvider.when('/bar', rdo); |
| 913 | + }); |
| 914 | + |
| 915 | + inject(function($location, $rootScope, $route) { |
| 916 | + $location.path('/bar'); |
| 917 | + $rootScope.$digest(); |
| 918 | + expect($location.path()).toBe('/bar'); |
| 919 | + expect($route.current.templateUrl).toBe('bar.html'); |
| 920 | + |
| 921 | + $location.path('/foo'); |
| 922 | + $rootScope.$digest(); |
| 923 | + expect($location.path()).toBe('/foo'); |
| 924 | + expect($route.current.templateUrl).toBe('foo.html'); |
| 925 | + }); |
| 926 | + } |
| 927 | + ); |
| 928 | + |
| 929 | + |
| 930 | + it('should use the property values of the passed in route definition object directly', |
| 931 | + function() { |
| 932 | + var $routeProvider; |
| 933 | + |
| 934 | + module(function(_$routeProvider_) { |
| 935 | + $routeProvider = _$routeProvider_; |
| 936 | + }); |
| 937 | + |
| 938 | + inject(function($location, $rootScope, $route, $sce) { |
| 939 | + var sceWrappedUrl = $sce.trustAsResourceUrl('foo.html'); |
| 940 | + $routeProvider.when('/foo', {templateUrl: sceWrappedUrl}); |
| 941 | + |
| 942 | + $location.path('/foo'); |
| 943 | + $rootScope.$digest(); |
| 944 | + expect($location.path()).toBe('/foo'); |
| 945 | + expect($route.current.templateUrl).toBe(sceWrappedUrl); |
| 946 | + }); |
| 947 | + } |
| 948 | + ); |
| 949 | + |
| 950 | + |
| 951 | + it('should support custom `$sce` implementations', function() { |
| 952 | + function MySafeResourceUrl(val) { |
| 953 | + var self = this; |
| 954 | + this._val = val; |
| 955 | + this.getVal = function() { |
| 956 | + return (this !== self) ? null : this._val; |
| 957 | + }; |
| 958 | + } |
| 959 | + |
| 960 | + var $routeProvider; |
| 961 | + |
| 962 | + module(function($provide, _$routeProvider_) { |
| 963 | + $routeProvider = _$routeProvider_; |
| 964 | + |
| 965 | + $provide.decorator('$sce', function($delegate) { |
| 966 | + $delegate.trustAsResourceUrl = function(url) { return new MySafeResourceUrl(url); }; |
| 967 | + $delegate.getTrustedResourceUrl = function(v) { return v.getVal(); }; |
| 968 | + $delegate.valueOf = function(v) { return v.getVal(); }; |
| 969 | + return $delegate; |
| 970 | + }); |
| 971 | + }); |
| 972 | + |
| 973 | + inject(function($location, $rootScope, $route, $sce) { |
| 974 | + $routeProvider.when('/foo', {templateUrl: $sce.trustAsResourceUrl('foo.html')}); |
| 975 | + |
| 976 | + $location.path('/foo'); |
| 977 | + $rootScope.$digest(); |
| 978 | + expect($location.path()).toBe('/foo'); |
| 979 | + expect($sce.valueOf($route.current.templateUrl)).toBe('foo.html'); |
| 980 | + }); |
| 981 | + }); |
| 982 | + |
| 983 | + |
903 | 984 | describe('redirection', function() {
|
904 | 985 | it('should support redirection via redirectTo property by updating $location', function() {
|
905 | 986 | module(function($routeProvider) {
|
|
0 commit comments