diff options
| author | Lucas Galfasó | 2013-04-29 19:07:05 +0100 |
|---|---|---|
| committer | Igor Minar | 2013-05-21 14:41:22 -0700 |
| commit | 4d8b0282b4e1d2de7948d3195f68c20b3c3765c2 (patch) | |
| tree | 95ad091d88b84631349b3cc3ea1248392cc7b73e /test | |
| parent | 00845fca88ae268e2c95812f7d500fe78198937c (diff) | |
| download | angular.js-4d8b0282b4e1d2de7948d3195f68c20b3c3765c2.tar.bz2 | |
test(parse): Test for the parsing not invoking twice to get self
New tests to not call twice a function to get self
Diffstat (limited to 'test')
| -rw-r--r-- | test/ng/parseSpec.js | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 2bbbb836..6616026f 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -473,6 +473,112 @@ describe('parser', function() { }); + it('should call the function from the received instance and not from a new one', function() { + var n = 0; + scope.fn = function() { + var c = n++; + return { c: c, anotherFn: function() { return this.c == c; } }; + }; + expect(scope.$eval('fn().anotherFn()')).toBe(true); + }); + + + it('should call the function once when it is part of the context', function() { + var count = 0; + scope.fn = function() { + count++; + return { anotherFn: function() { return "lucas"; } }; + }; + expect(scope.$eval('fn().anotherFn()')).toBe('lucas'); + expect(count).toBe(1); + }); + + + it('should call the function once when it is not part of the context', function() { + var count = 0; + scope.fn = function() { + count++; + return function() { return 'lucas'; }; + }; + expect(scope.$eval('fn()()')).toBe('lucas'); + expect(count).toBe(1); + }); + + + it('should call the function once when it is not part of the context', function() { + var count = 0; + scope.fn = function() { + count++; + return function() { return 'lucas'; }; + }; + expect(scope.$eval('fn()()')).toBe('lucas'); + expect(count).toBe(1); + }); + + + it('should call the function once when it is part of the context on assignments', function() { + var count = 0; + var element = {}; + scope.fn = function() { + count++; + return element; + }; + expect(scope.$eval('fn().name = "lucas"')).toBe('lucas'); + expect(element.name).toBe('lucas'); + expect(count).toBe(1); + }); + + + it('should call the function once when it is part of the context on array lookups', function() { + var count = 0; + var element = []; + scope.fn = function() { + count++; + return element; + }; + expect(scope.$eval('fn()[0] = "lucas"')).toBe('lucas'); + expect(element[0]).toBe('lucas'); + expect(count).toBe(1); + }); + + + it('should call the function once when it is part of the context on array lookup function', function() { + var count = 0; + var element = [{anotherFn: function() { return 'lucas';} }]; + scope.fn = function() { + count++; + return element; + }; + expect(scope.$eval('fn()[0].anotherFn()')).toBe('lucas'); + expect(count).toBe(1); + }); + + + it('should call the function once when it is part of the context on array lookup function', function() { + var count = 0; + var element = {name: {anotherFn: function() { return 'lucas';} } }; + scope.fn = function() { + count++; + return element; + }; + expect(scope.$eval('fn().name.anotherFn()')).toBe('lucas'); + expect(count).toBe(1); + }); + + + it('should call the function once when it is part of a sub-expression', function() { + var count = 0; + scope.element = [{}]; + scope.fn = function() { + count++; + return 0; + }; + expect(scope.$eval('element[fn()].name = "lucas"')).toBe('lucas'); + expect(scope.element[0].name).toBe('lucas'); + expect(count).toBe(1); + }); + + describe('promises', function() { var deferred, promise, q; |
