diff options
| author | Misko Hevery | 2011-03-23 09:33:29 -0700 |
|---|---|---|
| committer | Vojta Jina | 2011-08-02 01:00:03 +0200 |
| commit | 8f0dcbab804180828d6859b1340c86cf161209fb (patch) | |
| tree | d13d47d47a1889cb7c96a87cecacd2e25307d51c /test/service/locationSpec.js | |
| parent | 1f4b417184ce53af15474de065400f8a686430c5 (diff) | |
| download | angular.js-8f0dcbab804180828d6859b1340c86cf161209fb.tar.bz2 | |
feat(scope): new and improved scope implementation
- Speed improvements (about 4x on flush phase)
- Memory improvements (uses no function closures)
- Break $eval into $apply, $dispatch, $flush
- Introduced $watch and $observe
Breaks angular.equals() use === instead of ==
Breaks angular.scope() does not take parent as first argument
Breaks scope.$watch() takes scope as first argument
Breaks scope.$set(), scope.$get are removed
Breaks scope.$config is removed
Breaks $route.onChange callback has not "this" bounded
Diffstat (limited to 'test/service/locationSpec.js')
| -rw-r--r-- | test/service/locationSpec.js | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/test/service/locationSpec.js b/test/service/locationSpec.js index f5a8c6b2..73e5e43e 100644 --- a/test/service/locationSpec.js +++ b/test/service/locationSpec.js @@ -46,9 +46,10 @@ describe('$location', function() { $location.update('http://www.angularjs.org/'); $location.update({path: '/a/b'}); expect($location.href).toEqual('http://www.angularjs.org/a/b'); - expect($browser.getUrl()).toEqual(origBrowserUrl); - scope.$eval(); expect($browser.getUrl()).toEqual('http://www.angularjs.org/a/b'); + $location.path = '/c'; + scope.$digest(); + expect($browser.getUrl()).toEqual('http://www.angularjs.org/c'); }); @@ -65,7 +66,7 @@ describe('$location', function() { it('should update hash on hashPath or hashSearch update', function() { $location.update('http://server/#path?a=b'); - scope.$eval(); + scope.$digest(); $location.update({hashPath: '', hashSearch: {}}); expect($location.hash).toEqual(''); @@ -74,10 +75,10 @@ describe('$location', function() { it('should update hashPath and hashSearch on $location.hash change upon eval', function(){ $location.update('http://server/#path?a=b'); - scope.$eval(); + scope.$digest(); $location.hash = ''; - scope.$eval(); + scope.$digest(); expect($location.href).toEqual('http://server/'); expect($location.hashPath).toEqual(''); @@ -88,11 +89,13 @@ describe('$location', function() { it('should update hash on $location.hashPath or $location.hashSearch change upon eval', function() { $location.update('http://server/#path?a=b'); - scope.$eval(); + expect($location.href).toEqual('http://server/#path?a=b'); + expect($location.hashPath).toEqual('path'); + expect($location.hashSearch).toEqual({a:'b'}); + $location.hashPath = ''; $location.hashSearch = {}; - - scope.$eval(); + scope.$digest(); expect($location.href).toEqual('http://server/'); expect($location.hash).toEqual(''); @@ -103,14 +106,14 @@ describe('$location', function() { scope.$location = scope.$service('$location'); //publish to the scope for $watch var log = ''; - scope.$watch('$location.hash', function(){ - log += this.$location.hashPath + ';'; - }); + scope.$watch('$location.hash', function(scope){ + log += scope.$location.hashPath + ';'; + })(); expect(log).toEqual(';'); log = ''; scope.$location.hash = '/abc'; - scope.$eval(); + scope.$digest(); expect(scope.$location.hash).toEqual('/abc'); expect(log).toEqual('/abc;'); }); @@ -120,7 +123,7 @@ describe('$location', function() { it('should update hash with escaped hashPath', function() { $location.hashPath = 'foo=bar'; - scope.$eval(); + scope.$digest(); expect($location.hash).toBe('foo%3Dbar'); }); @@ -133,7 +136,7 @@ describe('$location', function() { $location.host = 'host'; $location.href = 'https://hrefhost:23/hrefpath'; - scope.$eval(); + scope.$digest(); expect($location).toEqualData({href: 'https://hrefhost:23/hrefpath', protocol: 'https', @@ -156,7 +159,7 @@ describe('$location', function() { $location.host = 'host'; $location.path = '/path'; - scope.$eval(); + scope.$digest(); expect($location).toEqualData({href: 'http://host:333/path#hash', protocol: 'http', @@ -237,7 +240,7 @@ describe('$location', function() { expect($location.href).toBe('http://server'); expect($location.hash).toBe(''); - scope.$eval(); + scope.$digest(); expect($location.href).toBe('http://server'); expect($location.hash).toBe(''); |
