From ce7ab3d1ee0e496c4b9838950b56fc1555b5bcf0 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Sun, 30 Jan 2011 16:57:57 -0800 Subject: add support for 404 handling via $route.otherwise Closes #217 --- test/servicesSpec.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index c4fadec8..02e874fe 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -411,6 +411,38 @@ describe("service", function(){ expect($route.current.controller).toBeUndefined(); expect(onChangeSpy).toHaveBeenCalled(); }); + + it('should handle unknown routes with "otherwise" route definition', function() { + var scope = angular.scope(), + $location = scope.$service('$location'), + $route = scope.$service('$route'), + onChangeSpy = jasmine.createSpy('onChange'); + + function NotFoundCtrl() {this.notFoundProp = 'not found!'} + + $route.when('/foo', {template: 'foo.html'}); + $route.otherwise({template: '404.html', controller: NotFoundCtrl}); + $route.onChange(onChangeSpy); + expect($route.current).toBeNull(); + expect(onChangeSpy).not.toHaveBeenCalled(); + + $location.updateHash('/unknownRoute'); + scope.$eval(); + + expect($route.current.template).toBe('404.html'); + expect($route.current.controller).toBe(NotFoundCtrl); + expect($route.current.scope.notFoundProp).toBe('not found!'); + expect(onChangeSpy).toHaveBeenCalled(); + + onChangeSpy.reset(); + $location.updateHash('/foo'); + scope.$eval(); + + expect($route.current.template).toEqual('foo.html'); + expect($route.current.controller).toBeUndefined(); + expect($route.current.scope.notFoundProp).toBeUndefined(); + expect(onChangeSpy).toHaveBeenCalled(); + }); }); -- cgit v1.2.3