diff options
| author | Igor Minar | 2011-01-31 23:26:10 -0800 | 
|---|---|---|
| committer | Igor Minar | 2011-02-01 09:35:19 -0800 | 
| commit | 6c0cf17404e8e6de0c398fff8e71497f39090408 (patch) | |
| tree | e77f95e0d9d7749c813e410f4bb0bc3b0346733f /test | |
| parent | c648fee5c2c46cbd2ea8b5bd4cec8005f182db1c (diff) | |
| download | angular.js-6c0cf17404e8e6de0c398fff8e71497f39090408.tar.bz2 | |
add redirection support to $route
Closes #217
Diffstat (limited to 'test')
| -rw-r--r-- | test/servicesSpec.js | 43 | 
1 files changed, 43 insertions, 0 deletions
| diff --git a/test/servicesSpec.js b/test/servicesSpec.js index f7151dbc..ddad5d89 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -460,6 +460,49 @@ describe("service", function(){        expect($route.current.scope.notFoundProp).toBeUndefined();        expect(onChangeSpy).toHaveBeenCalled();      }); + +    it('should support redirection via redirectTo property by updating $location', function() { +      var scope = angular.scope(), +          $location = scope.$service('$location'), +          $browser = scope.$service('$browser'), +          $route = scope.$service('$route'), +          onChangeSpy = jasmine.createSpy('onChange'); + +      $route.when('', {redirectTo: '/foo'}); +      $route.when('/foo', {template: 'foo.html'}); +      $route.when('/bar', {template: 'bar.html'}); +      $route.when('/baz', {redirectTo: '/bar'}); +      $route.otherwise({template: '404.html'}); +      $route.onChange(onChangeSpy); +      expect($route.current).toBeNull(); +      expect(onChangeSpy).not.toHaveBeenCalled(); + +      scope.$eval(); //triggers initial route change - match the redirect route +      $browser.poll(); //triger route change - match the route we redirected to + +      expect($location.hash).toBe('/foo'); +      expect($route.current.template).toBe('foo.html'); +      expect(onChangeSpy.callCount).toBe(1); + +      onChangeSpy.reset(); +      $location.updateHash(''); +      scope.$eval(); //match the redirect route + update $browser +      $browser.poll(); //match the route we redirected to + + +      expect($location.hash).toBe('/foo'); +      expect($route.current.template).toBe('foo.html'); +      expect(onChangeSpy.callCount).toBe(1); + +      onChangeSpy.reset(); +      $location.updateHash('/baz'); +      scope.$eval(); //match the redirect route + update $browser +      $browser.poll(); //match the route we redirected to + +      expect($location.hash).toBe('/bar'); +      expect($route.current.template).toBe('bar.html'); +      expect(onChangeSpy.callCount).toBe(1); +    });    }); | 
