2011-08-24 05:30:14 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2011-10-07 18:27:49 +00:00
|
|
|
describe('$routeParams', function() {
|
|
|
|
|
it('should publish the params into a service', function() {
|
2011-08-24 05:30:14 +00:00
|
|
|
var scope = angular.scope(),
|
|
|
|
|
$location = scope.$service('$location'),
|
|
|
|
|
$route = scope.$service('$route'),
|
|
|
|
|
$routeParams = scope.$service('$routeParams');
|
|
|
|
|
|
|
|
|
|
$route.when('/foo');
|
|
|
|
|
$route.when('/bar/:barId');
|
|
|
|
|
|
2011-07-12 00:18:17 +00:00
|
|
|
$location.path('/foo').search('a=b');
|
2011-08-24 05:30:14 +00:00
|
|
|
scope.$digest();
|
|
|
|
|
expect($routeParams).toEqual({a:'b'});
|
|
|
|
|
|
2011-07-12 00:18:17 +00:00
|
|
|
$location.path('/bar/123').search('x=abc');
|
2011-08-24 05:30:14 +00:00
|
|
|
scope.$digest();
|
|
|
|
|
expect($routeParams).toEqual({barId:'123', x:'abc'});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2011-10-07 18:27:49 +00:00
|
|
|
it('should preserve object identity during route reloads', function() {
|
2011-08-24 05:30:14 +00:00
|
|
|
var scope = angular.scope(),
|
|
|
|
|
$location = scope.$service('$location'),
|
|
|
|
|
$route = scope.$service('$route'),
|
|
|
|
|
$routeParams = scope.$service('$routeParams'),
|
|
|
|
|
firstRouteParams = $routeParams;
|
|
|
|
|
|
|
|
|
|
$route.when('/foo');
|
|
|
|
|
$route.when('/bar/:barId');
|
|
|
|
|
|
2011-07-12 00:18:17 +00:00
|
|
|
$location.path('/foo').search('a=b');
|
2011-08-24 05:30:14 +00:00
|
|
|
scope.$digest();
|
|
|
|
|
expect(scope.$service('$routeParams')).toBe(firstRouteParams);
|
|
|
|
|
|
2011-07-12 00:18:17 +00:00
|
|
|
$location.path('/bar/123').search('x=abc');
|
2011-08-24 05:30:14 +00:00
|
|
|
scope.$digest();
|
|
|
|
|
expect(scope.$service('$routeParams')).toBe(firstRouteParams);
|
|
|
|
|
});
|
|
|
|
|
});
|