aboutsummaryrefslogtreecommitdiffstats
path: root/test/service/routeParamsSpec.js
blob: 972e4314cce5d79cb100b344e8957b8805825ea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';

describe('$routeParams', function() {
  it('should publish the params into a service', function() {
    var scope = angular.scope(),
        $location = scope.$service('$location'),
        $route = scope.$service('$route'),
        $routeParams = scope.$service('$routeParams');

    $route.when('/foo');
    $route.when('/bar/:barId');

    $location.path('/foo').search('a=b');
    scope.$digest();
    expect($routeParams).toEqual({a:'b'});

    $location.path('/bar/123').search('x=abc');
    scope.$digest();
    expect($routeParams).toEqual({barId:'123', x:'abc'});
  });


  it('should preserve object identity during route reloads', function() {
    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');

    $location.path('/foo').search('a=b');
    scope.$digest();
    expect(scope.$service('$routeParams')).toBe(firstRouteParams);

    $location.path('/bar/123').search('x=abc');
    scope.$digest();
    expect(scope.$service('$routeParams')).toBe(firstRouteParams);
  });
});