diff options
| author | Igor Minar | 2010-11-17 22:32:35 -0800 |
|---|---|---|
| committer | Igor Minar | 2010-11-18 02:35:29 -0800 |
| commit | 522ec1a9ec10e1fece3e5e855c1d7ef9770a8efc (patch) | |
| tree | c4ae99f716539745d45b55e09e1aa6537db372e1 /test | |
| parent | 9cb57772a4030925318475fe93bc19e2916b37bf (diff) | |
| download | angular.js-522ec1a9ec10e1fece3e5e855c1d7ef9770a8efc.tar.bz2 | |
move attribute widgets to widgets.js file
- move @ng:repeat to widgets.js and its specs to widgetsSpecs.js
- move @ng:non-bindable to widgets.js and its specs to widgetsSpecs.js
- make widget.template suitable for attribute widgets
- fix up the js docs for attribute widgets
Diffstat (limited to 'test')
| -rw-r--r-- | test/directivesSpec.js | 79 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 81 |
2 files changed, 82 insertions, 78 deletions
diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 4b949fcb..b70067ba 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -1,4 +1,4 @@ -describe("directives", function(){ +describe("directive", function(){ var compile, model, element; @@ -128,83 +128,6 @@ describe("directives", function(){ expect(input.checked).toEqual(true); }); - it('should ng:non-bindable', function(){ - var scope = compile('<div ng:non-bindable><span ng:bind="name"></span></div>'); - scope.$set('name', 'misko'); - scope.$eval(); - expect(element.text()).toEqual(''); - }); - - - describe('ng:repeat', function() { - - 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; - - 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.match(/Expected ng:repeat in form of 'item in collection' but got 'i dont parse'./)).toBeTruthy(); - }); - - 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(); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 03eb3acd..d3957e66 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -11,6 +11,7 @@ describe("widget", function(){ (before||noop).apply(scope); if (parent) parent.append(element); scope.$init(); + return scope; }; }); @@ -581,5 +582,85 @@ describe("widget", function(){ expect(document.location.href).toEqual(orgLocation); }); }); + + + describe('@ng:repeat', function() { + + 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; + + 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.match(/Expected ng:repeat in form of 'item in collection' but got 'i dont parse'./)).toBeTruthy(); + }); + + 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|'); + }); + }); + + + describe('@ng:non-bindable', function() { + + it('should prevent compilation of the owning element and its children', function(){ + var scope = compile('<div ng:non-bindable><span ng:bind="name"></span></div>'); + scope.$set('name', 'misko'); + scope.$eval(); + expect(element.text()).toEqual(''); + }); + }); }); |
