From 522ec1a9ec10e1fece3e5e855c1d7ef9770a8efc Mon Sep 17 00:00:00 2001
From: Igor Minar
Date: Wed, 17 Nov 2010 22:32:35 -0800
Subject: 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
---
test/directivesSpec.js | 79 +-----------------------------------------------
test/widgetsSpec.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 78 deletions(-)
(limited to 'test')
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('
');
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('
');
+
+ 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('
');
+ 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('
');
+ 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('
');
+ 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('
');
+ 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('
');
+ 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('
');
+ 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('
');
+ scope.$set('name', 'misko');
+ scope.$eval();
+ expect(element.text()).toEqual('');
+ });
+ });
});
--
cgit v1.2.3