aboutsummaryrefslogtreecommitdiffstats
path: root/test/ngRoute/routeParamsSpec.js
diff options
context:
space:
mode:
authorIgor Minar2013-06-05 15:30:31 -0700
committerIgor Minar2013-06-06 17:07:12 -0700
commit5599b55b04788c2e327d7551a4a699d75516dd21 (patch)
treedc080ce9639f44056eb6c476fb030923249ce265 /test/ngRoute/routeParamsSpec.js
parent7a5cfb593f27c28cee545974736632bf8da62fe8 (diff)
downloadangular.js-5599b55b04788c2e327d7551a4a699d75516dd21.tar.bz2
refactor($route): pull $route and friends into angular-route.js
$route, $routeParams and ngView have been pulled from core angular.js to angular-route.js/ngRoute module. This is was done to in order keep the core focused on most commonly used functionality and allow community routers to be freely used instead of $route service. There is no need to panic, angular-route will keep on being supported by the angular team. Note: I'm intentionally not fixing tutorial links. Tutorial will need bigger changes and those should be done when we update tutorial to 1.2. BREAKING CHANGE: applications that use $route will now need to load angular-route.js file and define dependency on ngRoute module. Before: ``` ... <script src="angular.js"></script> ... var myApp = angular.module('myApp', ['someOtherModule']); ... ``` After: ``` ... <script src="angular.js"></script> <script src="angular-route.js"></script> ... var myApp = angular.module('myApp', ['ngRoute', 'someOtherModule']); ... ``` Closes #2804
Diffstat (limited to 'test/ngRoute/routeParamsSpec.js')
-rw-r--r--test/ngRoute/routeParamsSpec.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/ngRoute/routeParamsSpec.js b/test/ngRoute/routeParamsSpec.js
new file mode 100644
index 00000000..1391151c
--- /dev/null
+++ b/test/ngRoute/routeParamsSpec.js
@@ -0,0 +1,48 @@
+'use strict';
+
+describe('$routeParams', function() {
+
+ beforeEach(module('ngRoute'));
+
+
+ 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'});
+ });
+ });
+});