mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Commit 773ac4a broke support for route parameters that are not seperated from other route parts by slashes, which this change fixes. It also adds some documentation about path parameters to the when() method and escapes all regular expression special characters in the URL, not just some.
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
describe('$routeParams', function() {
|
|
it('should publish the params into a service', function() {
|
|
module(function($routeProvider) {
|
|
$routeProvider.when('/foo', {});
|
|
$routeProvider.when('/bar/:barId', {});
|
|
});
|
|
|
|
inject(function($rootScope, $route, $location, $routeParams) {
|
|
$location.path('/foo').search('a=b');
|
|
$rootScope.$digest();
|
|
expect($routeParams).toEqual({a:'b'});
|
|
|
|
$location.path('/bar/123').search('x=abc');
|
|
$rootScope.$digest();
|
|
expect($routeParams).toEqual({barId:'123', x:'abc'});
|
|
});
|
|
});
|
|
|
|
it('should correctly extract the params when a param name is part of the route', function() {
|
|
module(function($routeProvider) {
|
|
$routeProvider.when('/bar/:foo/:bar', {});
|
|
});
|
|
|
|
inject(function($rootScope, $route, $location, $routeParams) {
|
|
$location.path('/bar/foovalue/barvalue');
|
|
$rootScope.$digest();
|
|
expect($routeParams).toEqual({bar:'barvalue', foo:'foovalue'});
|
|
});
|
|
});
|
|
|
|
it('should support route params not preceded by slashes', function() {
|
|
module(function($routeProvider) {
|
|
$routeProvider.when('/bar:barId/foo:fooId/', {});
|
|
});
|
|
|
|
inject(function($rootScope, $route, $location, $routeParams) {
|
|
$location.path('/barbarvalue/foofoovalue/');
|
|
$rootScope.$digest();
|
|
expect($routeParams).toEqual({barId: 'barvalue', fooId: 'foovalue'});
|
|
});
|
|
});
|
|
});
|