diff options
| author | Misko Hevery | 2010-04-15 14:17:33 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-04-15 14:17:33 -0700 |
| commit | 70e401ef100614295fc808e32f0142f07c315461 (patch) | |
| tree | 7d31580fb512dd535465e4d42afb0252b0cf0071 /test/servicesSpec.js | |
| parent | cd03fe92a5dbd2aba516b64fc8067c5fba1e4a81 (diff) | |
| download | angular.js-70e401ef100614295fc808e32f0142f07c315461.tar.bz2 | |
added $route service
Diffstat (limited to 'test/servicesSpec.js')
| -rw-r--r-- | test/servicesSpec.js | 38 |
1 files changed, 38 insertions, 0 deletions
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 = '<init>'; + } + BookChapter.prototype.init = function(){ + log += 'init();'; + }; + var scope = compile('<div></div>').$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('<init>'); + 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); + + }); +}); |
