From 70e401ef100614295fc808e32f0142f07c315461 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 15 Apr 2010 14:17:33 -0700 Subject: added $route service --- test/servicesSpec.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/servicesSpec.js') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 618d9a15..715a232e 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -99,3 +99,41 @@ describe("service $invalidWidgets", function(){ expect(scope.$invalidWidgets.length).toEqual(0); }); }); + +describe("service $route", function(){ + it('should route and fire change event', function(){ + var log = ''; + function BookChapter() { + this.log = ''; + } + BookChapter.prototype.init = function(){ + log += 'init();'; + }; + var scope = compile('
').$init(); + scope.$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); + scope.$route.when('/Blank'); + scope.$route.onChange(function(){ + log += 'onChange();'; + }); + scope.$location.parse('http://server#/Book/Moby/Chapter/Intro?p=123'); + scope.$eval(); + expect(log).toEqual('onChange();init();'); + expect(scope.$route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); + expect(scope.$route.current.scope.log).toEqual(''); + var lastId = scope.$route.current.scope.$id; + + log = ''; + scope.$location.parse('http://server#/Blank?ignore'); + scope.$eval(); + expect(log).toEqual('onChange();'); + expect(scope.$route.current.params).toEqual({ignore:true}); + expect(scope.$route.current.scope.$id).not.toEqual(lastId); + + log = ''; + scope.$location.parse('http://server#/NONE'); + scope.$eval(); + expect(log).toEqual('onChange();'); + expect(scope.$route.current).toEqual(null); + + }); +}); -- cgit v1.2.3