diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/directivesSpec.js | 89 |
1 files changed, 63 insertions, 26 deletions
diff --git a/test/directivesSpec.js b/test/directivesSpec.js index a3aa2481..d575c062 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -135,39 +135,76 @@ describe("directives", function(){ expect(element.text()).toEqual(''); }); - it('should ng:repeat over array', function(){ - var scope = compile('<ul><li ng:repeat="item in items" ng:init="suffix = \';\'" ng:bind="item + suffix"></li></ul>'); - Array.prototype.extraProperty = "should be ignored"; - scope.items = ['misko', 'shyam']; - scope.$eval(); - expect(element.text()).toEqual('misko;shyam;'); - delete Array.prototype.extraProperty; + describe('ng:repeat', function() { - scope.items = ['adam', 'kai', 'brad']; - scope.$eval(); - expect(element.text()).toEqual('adam;kai;brad;'); + it('should ng:repeat over array', function(){ + var scope = compile('<ul><li ng:repeat="item in items" ng:init="suffix = \';\'" ng:bind="item + suffix"></li></ul>'); - scope.items = ['brad']; - scope.$eval(); - expect(element.text()).toEqual('brad;'); - }); + Array.prototype.extraProperty = "should be ignored"; + scope.items = ['misko', 'shyam']; + scope.$eval(); + expect(element.text()).toEqual('misko;shyam;'); + delete Array.prototype.extraProperty; - it('should ng:repeat over object', function(){ - var scope = compile('<ul><li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li></ul>'); - scope.$set('items', {misko:'swe', shyam:'set'}); - scope.$eval(); - expect(element.text()).toEqual('misko:swe;shyam:set;'); - }); + scope.items = ['adam', 'kai', 'brad']; + scope.$eval(); + expect(element.text()).toEqual('adam;kai;brad;'); + + scope.items = ['brad']; + scope.$eval(); + expect(element.text()).toEqual('brad;'); + }); + + it('should ng:repeat over object', function(){ + var scope = compile('<ul><li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li></ul>'); + scope.$set('items', {misko:'swe', shyam:'set'}); + scope.$eval(); + expect(element.text()).toEqual('misko:swe;shyam:set;'); + }); - it('should error on wrong parsing of ng:repeat', function(){ - var scope = compile('<ul><li ng:repeat="i dont parse"></li></ul>'); - var log = ""; - log += element.attr('ng-exception') + ';'; - log += element.hasClass('ng-exception') + ';'; - expect(log).toEqual("\"Expected ng:repeat in form of 'item in collection' but got 'i dont parse'.\";true;"); + it('should error on wrong parsing of ng:repeat', function(){ + var scope = compile('<ul><li ng:repeat="i dont parse"></li></ul>'); + var log = ""; + log += element.attr('ng-exception') + ';'; + log += element.hasClass('ng-exception') + ';'; + expect(log).toEqual("\"Expected ng:repeat in form of 'item in collection' but got 'i dont parse'.\";true;"); + }); + + it('should expose iterator offset as $index when iterating over arrays', function() { + var scope = compile('<ul><li ng:repeat="item in items" ' + + 'ng:bind="item + $index + \'|\'"></li></ul>'); + scope.items = ['misko', 'shyam', 'frodo']; + scope.$eval(); + expect(element.text()).toEqual('misko0|shyam1|frodo2|'); + }); + + it('should expose iterator offset as $index when iterating over objects', function() { + var scope = compile('<ul><li ng:repeat="(key, val) in items" ' + + 'ng:bind="key + \':\' + val + $index + \'|\'"></li></ul>'); + scope.items = {'misko':'m', 'shyam':'s', 'frodo':'f'}; + scope.$eval(); + expect(element.text()).toEqual('misko:m0|shyam:s1|frodo:f2|'); + }); + + it('should expose iterator position as $position when iterating over arrays', function() { + var scope = compile('<ul><li ng:repeat="item in items" ' + + 'ng:bind="item + \':\' + $position + \'|\'"></li></ul>'); + scope.items = ['misko', 'shyam', 'doug', 'frodo']; + scope.$eval(); + expect(element.text()).toEqual('misko:first|shyam:middle|doug:middle|frodo:last|'); + }); + + it('should expose iterator position as $position when iterating over objects', function() { + var scope = compile('<ul><li ng:repeat="(key, val) in items" ' + + 'ng:bind="key + \':\' + val + \':\' + $position + \'|\'"></li></ul>'); + scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'}; + scope.$eval(); + expect(element.text()).toEqual('misko:m:first|shyam:s:middle|doug:d:middle|frodo:f:last|'); + }); }); + it('should ng:watch', function(){ var scope = compile('<div ng:watch="i: count = count + 1" ng:init="count = 0">'); scope.$eval(); |
