diff options
Diffstat (limited to 'test/servicesSpec.js')
| -rw-r--r-- | test/servicesSpec.js | 113 |
1 files changed, 65 insertions, 48 deletions
diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 715a232e..f917f968 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -9,53 +9,6 @@ describe("services", function(){ expect(scope.$window).toEqual(window); }); - it("should inject $location", function(){ - scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value'); - expect(scope.$location.href).toEqual("http://host:123/p/a/t/h.html?query=value#path?key=value"); - expect(scope.$location.protocol).toEqual("http"); - expect(scope.$location.host).toEqual("host"); - expect(scope.$location.port).toEqual("123"); - expect(scope.$location.path).toEqual("/p/a/t/h.html"); - expect(scope.$location.search).toEqual({query:'value'}); - expect(scope.$location.hash).toEqual('path?key=value'); - expect(scope.$location.hashPath).toEqual('path'); - expect(scope.$location.hashSearch).toEqual({key:'value'}); - - scope.$location.hashPath = 'page=http://path'; - scope.$location.hashSearch = {k:'a=b'}; - - expect(scope.$location.toString()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db'); - }); - - it('should parse file://', function(){ - scope.$location.parse('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html'); - expect(scope.$location.href).toEqual("file:///Users/Shared/misko/work/angular.js/scenario/widgets.html"); - expect(scope.$location.protocol).toEqual("file"); - expect(scope.$location.host).toEqual(""); - expect(scope.$location.port).toEqual(null); - expect(scope.$location.path).toEqual("/Users/Shared/misko/work/angular.js/scenario/widgets.html"); - expect(scope.$location.search).toEqual({}); - expect(scope.$location.hash).toEqual(''); - expect(scope.$location.hashPath).toEqual(''); - expect(scope.$location.hashSearch).toEqual({}); - - expect(scope.$location.toString()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#'); - }); - - it('should update url on hash change', function(){ - scope.$location.parse('http://server/#path?a=b'); - scope.$location.hash = ''; - expect(scope.$location.toString()).toEqual('http://server/#'); - expect(scope.$location.hashPath).toEqual(''); - }); - - it('should update url on hashPath change', function(){ - scope.$location.parse('http://server/#path?a=b'); - scope.$location.hashPath = ''; - expect(scope.$location.toString()).toEqual('http://server/#?a=b'); - expect(scope.$location.hash).toEqual('?a=b'); - }); - xit('should add stylesheets', function(){ scope.$document = { getElementsByTagName: function(name){ @@ -64,9 +17,71 @@ describe("services", function(){ } }; scope.$document.addStyleSheet('css/angular.css'); - }); + describe("$location", function(){ + it("should inject $location", function(){ + scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value'); + expect(scope.$location.href).toEqual("http://host:123/p/a/t/h.html?query=value#path?key=value"); + expect(scope.$location.protocol).toEqual("http"); + expect(scope.$location.host).toEqual("host"); + expect(scope.$location.port).toEqual("123"); + expect(scope.$location.path).toEqual("/p/a/t/h.html"); + expect(scope.$location.search).toEqual({query:'value'}); + expect(scope.$location.hash).toEqual('path?key=value'); + expect(scope.$location.hashPath).toEqual('path'); + expect(scope.$location.hashSearch).toEqual({key:'value'}); + + scope.$location.hashPath = 'page=http://path'; + scope.$location.hashSearch = {k:'a=b'}; + + expect(scope.$location.toString()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db'); + }); + + it('should parse file://', function(){ + scope.$location.parse('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html'); + expect(scope.$location.href).toEqual("file:///Users/Shared/misko/work/angular.js/scenario/widgets.html"); + expect(scope.$location.protocol).toEqual("file"); + expect(scope.$location.host).toEqual(""); + expect(scope.$location.port).toEqual(null); + expect(scope.$location.path).toEqual("/Users/Shared/misko/work/angular.js/scenario/widgets.html"); + expect(scope.$location.search).toEqual({}); + expect(scope.$location.hash).toEqual(''); + expect(scope.$location.hashPath).toEqual(''); + expect(scope.$location.hashSearch).toEqual({}); + + expect(scope.$location.toString()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#'); + }); + + it('should update url on hash change', function(){ + scope.$location.parse('http://server/#path?a=b'); + scope.$location.hash = ''; + expect(scope.$location.toString()).toEqual('http://server/#'); + expect(scope.$location.hashPath).toEqual(''); + }); + + it('should update url on hashPath change', function(){ + scope.$location.parse('http://server/#path?a=b'); + scope.$location.hashPath = ''; + expect(scope.$location.toString()).toEqual('http://server/#?a=b'); + expect(scope.$location.hash).toEqual('?a=b'); + }); + + it('should update hash before any processing', function(){ + var scope = compile('<div>'); + var log = ''; + scope.$watch('$location.hash', function(){ + log += this.$location.hashPath + ';'; + }); + expect(log).toEqual(';'); + + log = ''; + scope.$location.hash = '/abc'; + scope.$eval(); + expect(log).toEqual('/abc;'); + }); + + }); }); describe("service $invalidWidgets", function(){ @@ -135,5 +150,7 @@ describe("service $route", function(){ expect(log).toEqual('onChange();'); expect(scope.$route.current).toEqual(null); + scope.$route.when('/NONE', {template:'instant update'}); + expect(scope.$route.current.template).toEqual('instant update'); }); }); |
