From 84552f7f8ac3f39c4dbd7d946ae2938d63302840 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Mon, 22 Mar 2010 13:58:04 -0700
Subject: got few directives working
---
test/directivesSpec.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 test/directivesSpec.js
(limited to 'test/directivesSpec.js')
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
new file mode 100644
index 00000000..176f9e70
--- /dev/null
+++ b/test/directivesSpec.js
@@ -0,0 +1,71 @@
+describe("directives", function(){
+
+ var compile, element;
+
+ beforeEach(function() {
+ var compiler = new Compiler(angularMarkup, angularDirective, angularWidget);
+ compile = function(html) {
+ element = jqLite(html);
+ var view = compiler.compile(element.element)(element.element);
+ view.init();
+ return view.scope;
+ };
+ });
+
+ it("should ng-init", function() {
+ var scope = compile('
');
+ scope.updateView();
+ scope.updateView();
+ expect(scope.get('count')).toEqual(0);
+
+ scope.set('i', 0);
+ scope.updateView();
+ scope.updateView();
+ expect(scope.get('count')).toEqual(1);
+ });
});
--
cgit v1.2.3
From 7c87c17d08dbba318af1a149c0bbedb696b03458 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Mon, 22 Mar 2010 18:20:49 -0700
Subject: upgraded jquery to 1.4.2 and made ng-action work with jquery
---
test/directivesSpec.js | 9 +++++++++
1 file changed, 9 insertions(+)
(limited to 'test/directivesSpec.js')
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index e0e53eeb..447698a3 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -94,4 +94,13 @@ describe("directives", function(){
scope.updateView();
expect(scope.get('count')).toEqual(1);
});
+
+ it('should ng-action', function(){
+ var scope = compile('
');
+ scope.updateView();
+ expect(scope.get('clicked')).toBeFalsy();
+
+ jQuery(element.element).click();
+ expect(scope.get('clicked')).toEqual(true);
+ });
});
--
cgit v1.2.3
From a8227086748e37c31c1bb71dec50c96d63c45eef Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Mon, 22 Mar 2010 20:20:05 -0700
Subject: rudementary event bind and trigger for jqlite
---
test/directivesSpec.js | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
(limited to 'test/directivesSpec.js')
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 447698a3..7e0446ef 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -12,6 +12,11 @@ describe("directives", function(){
};
});
+ afterEach(function(){
+ element.remove();
+ expect(_(jqCache).size()).toEqual(0);
+ });
+
it("should ng-init", function() {
var scope = compile('
');
expect(scope.get('a')).toEqual(123);
@@ -100,7 +105,7 @@ describe("directives", function(){
scope.updateView();
expect(scope.get('clicked')).toBeFalsy();
- jQuery(element.element).click();
+ element.click();
expect(scope.get('clicked')).toEqual(true);
});
});
--
cgit v1.2.3
From 6ff550cfa9524bbb124d10caf1fc13c911ab3b4b Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Mon, 22 Mar 2010 21:29:57 -0700
Subject: all angular.js directives now work
---
test/directivesSpec.js | 45 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
(limited to 'test/directivesSpec.js')
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 7e0446ef..d125d326 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -6,7 +6,7 @@ describe("directives", function(){
var compiler = new Compiler(angularMarkup, angularDirective, angularWidget);
compile = function(html) {
element = jqLite(html);
- var view = compiler.compile(element.element)(element.element);
+ var view = compiler.compile(element)(element);
view.init();
return view.scope;
};
@@ -108,4 +108,47 @@ describe("directives", function(){
element.click();
expect(scope.get('clicked')).toEqual(true);
});
+
+ it('should ng-class', function(){
+ var scope = compile('
');
+ scope.updateView();
+ expect(element.hasClass('existing')).toBeTruthy();
+ expect(element.hasClass('A')).toBeTruthy();
+ expect(element.hasClass('B')).toBeTruthy();
+ });
+
+ it('should ng-class odd/even', function(){
+ var scope = compile('
');
+ scope.updateView();
+ var e1 = jQuery(element.parent()[0]).find('li:first');
+ var e2 = jQuery(element.parent()[0]).find('li:last');
+ expect(e1.hasClass('existing')).toBeTruthy();
+ expect(e1.hasClass('even')).toBeTruthy();
+ expect(e2.hasClass('existing')).toBeTruthy();
+ expect(e2.hasClass('odd')).toBeTruthy();
+ });
+
+ it('should ng-style', function(){
+ var scope = compile('');
+ scope.updateView();
+ expect(element.css('color')).toEqual('red');
+ });
+
+ it('should ng-show', function(){
+ var scope = compile('');
+ scope.updateView();
+ expect(element.css('display')).toEqual('');
+ scope.set('hide', true);
+ scope.updateView();
+ expect(element.css('display')).toEqual('none');
+ });
+
+ it('should ng-hide', function(){
+ var scope = compile('');
+ scope.updateView();
+ expect(element.css('display')).toEqual('none');
+ scope.set('show', true);
+ scope.updateView();
+ expect(element.css('display')).toEqual('');
+ });
});
--
cgit v1.2.3
From bb98ae14f2aef74efbd8345e93f62ac67f460f7f Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Tue, 23 Mar 2010 14:57:11 -0700
Subject: markup now wroks, some refactorings
---
test/directivesSpec.js | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
(limited to 'test/directivesSpec.js')
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index d125d326..18bedb64 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -3,7 +3,7 @@ describe("directives", function(){
var compile, element;
beforeEach(function() {
- var compiler = new Compiler(angularMarkup, angularDirective, angularWidget);
+ var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
compile = function(html) {
element = jqLite(html);
var view = compiler.compile(element)(element);
@@ -39,6 +39,14 @@ describe("directives", function(){
expect(element.text()).toEqual('misko');
});
+ it('should ng-bind-template', function() {
+ var scope = compile('');
+ expect(element.text()).toEqual('');
+ scope.set('name', 'Misko');
+ scope.updateView();
+ expect(element.text()).toEqual('Hello Misko!');
+ });
+
it('should ng-bind-attr', function(){
var scope = compile('
');
expect(element.attr('src')).toEqual(null);
@@ -81,7 +89,7 @@ describe("directives", function(){
it('should error on wrong parsing of ng-repeat', function(){
var scope = compile('');
var log = "";
- element.eachNode(function(li){
+ eachNode(element, function(li){
log += li.attr('ng-error') + ';';
log += li.hasClass('ng-exception') + ';';
});
--
cgit v1.2.3
From b814c79b58deeeeaa12b03261399ef80c0d6cc9f Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Thu, 25 Mar 2010 13:01:08 -0700
Subject: checkbox and radio now working
---
test/directivesSpec.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test/directivesSpec.js')
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 18bedb64..83a270c1 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -12,7 +12,7 @@ describe("directives", function(){
};
});
- afterEach(function(){
+ afterEach(function() {
element.remove();
expect(_(jqCache).size()).toEqual(0);
});
--
cgit v1.2.3
From d934054cfc22325d817eb0643dc061f9d212804d Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Thu, 25 Mar 2010 22:03:11 -0700
Subject: major refactoring of scope
---
test/directivesSpec.js | 96 ++++++++++++++++++++++++--------------------------
1 file changed, 47 insertions(+), 49 deletions(-)
(limited to 'test/directivesSpec.js')
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 83a270c1..4ef57dce 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -1,49 +1,49 @@
describe("directives", function(){
- var compile, element;
+ var compile, model, element;
beforeEach(function() {
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
compile = function(html) {
element = jqLite(html);
- var view = compiler.compile(element)(element);
- view.init();
- return view.scope;
+ model = compiler.compile(element)(element);
+ model.$init();
+ return model;
};
});
afterEach(function() {
- element.remove();
+ model.$element.remove();
expect(_(jqCache).size()).toEqual(0);
});
it("should ng-init", function() {
var scope = compile('');
- expect(scope.get('a')).toEqual(123);
+ expect(scope.a).toEqual(123);
});
it("should ng-eval", function() {
var scope = compile('');
- expect(scope.get('a')).toEqual(0);
- scope.updateView();
- expect(scope.get('a')).toEqual(1);
- scope.updateView();
- expect(scope.get('a')).toEqual(2);
+ expect(scope.a).toEqual(0);
+ scope.$eval();
+ expect(scope.a).toEqual(1);
+ scope.$eval();
+ expect(scope.a).toEqual(2);
});
it('should ng-bind', function() {
var scope = compile('');
expect(element.text()).toEqual('');
- scope.set('a', 'misko');
- scope.updateView();
+ scope.a = 'misko';
+ scope.$eval();
expect(element.text()).toEqual('misko');
});
it('should ng-bind-template', function() {
var scope = compile('');
expect(element.text()).toEqual('');
- scope.set('name', 'Misko');
- scope.updateView();
+ scope.$set('name', 'Misko');
+ scope.$eval();
expect(element.text()).toEqual('Hello Misko!');
});
@@ -51,75 +51,73 @@ describe("directives", function(){
var scope = compile('
');
expect(element.attr('src')).toEqual(null);
expect(element.attr('alt')).toEqual(null);
- scope.updateView();
+ scope.$eval();
expect(element.attr('src')).toEqual('mysrc');
expect(element.attr('alt')).toEqual('myalt');
});
it('should ng-non-bindable', function(){
var scope = compile('
');
- scope.set('name', 'misko');
- scope.updateView();
+ scope.$set('name', 'misko');
+ scope.$eval();
expect(element.text()).toEqual('');
});
it('should ng-repeat over array', function(){
var scope = compile('');
- scope.set('items', ['misko', 'shyam']);
- scope.updateView();
+ scope.$set('items', ['misko', 'shyam']);
+ scope.$eval();
expect(element.text()).toEqual('misko;shyam;');
- scope.set('items', ['adam', 'kai', 'brad']);
- scope.updateView();
+ scope.$set('items', ['adam', 'kai', 'brad']);
+ scope.$eval();
expect(element.text()).toEqual('adam;kai;brad;');
- scope.set('items', ['brad']);
- scope.updateView();
+ scope.$set('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.updateView();
+ 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 = "";
- eachNode(element, function(li){
- log += li.attr('ng-error') + ';';
- log += li.hasClass('ng-exception') + ';';
- });
+ log += element.attr('ng-error') + ';';
+ 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 ng-watch', function(){
var scope = compile('');
- scope.updateView();
- scope.updateView();
- expect(scope.get('count')).toEqual(0);
+ scope.$eval();
+ scope.$eval();
+ expect(scope.$get('count')).toEqual(0);
- scope.set('i', 0);
- scope.updateView();
- scope.updateView();
- expect(scope.get('count')).toEqual(1);
+ scope.$set('i', 0);
+ scope.$eval();
+ scope.$eval();
+ expect(scope.$get('count')).toEqual(1);
});
it('should ng-action', function(){
var scope = compile('
');
- scope.updateView();
- expect(scope.get('clicked')).toBeFalsy();
+ scope.$eval();
+ expect(scope.$get('clicked')).toBeFalsy();
element.click();
- expect(scope.get('clicked')).toEqual(true);
+ expect(scope.$get('clicked')).toEqual(true);
});
it('should ng-class', function(){
var scope = compile('
');
- scope.updateView();
+ scope.$eval();
expect(element.hasClass('existing')).toBeTruthy();
expect(element.hasClass('A')).toBeTruthy();
expect(element.hasClass('B')).toBeTruthy();
@@ -127,7 +125,7 @@ describe("directives", function(){
it('should ng-class odd/even', function(){
var scope = compile('
');
- scope.updateView();
+ scope.$eval();
var e1 = jQuery(element.parent()[0]).find('li:first');
var e2 = jQuery(element.parent()[0]).find('li:last');
expect(e1.hasClass('existing')).toBeTruthy();
@@ -138,25 +136,25 @@ describe("directives", function(){
it('should ng-style', function(){
var scope = compile('');
- scope.updateView();
+ scope.$eval();
expect(element.css('color')).toEqual('red');
});
it('should ng-show', function(){
var scope = compile('');
- scope.updateView();
+ scope.$eval();
expect(element.css('display')).toEqual('');
- scope.set('hide', true);
- scope.updateView();
+ scope.$set('hide', true);
+ scope.$eval();
expect(element.css('display')).toEqual('none');
});
it('should ng-hide', function(){
var scope = compile('');
- scope.updateView();
+ scope.$eval();
expect(element.css('display')).toEqual('none');
- scope.set('show', true);
- scope.updateView();
+ scope.$set('show', true);
+ scope.$eval();
expect(element.css('display')).toEqual('');
});
});
--
cgit v1.2.3
From e55c97debaa0ef8487ece219b6eadbc147ece1f9 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Mon, 29 Mar 2010 20:25:42 -0700
Subject: dissabled a lot of tests, and made the core test set pass.
---
test/directivesSpec.js | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
(limited to 'test/directivesSpec.js')
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 4ef57dce..343698af 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -14,7 +14,7 @@ describe("directives", function(){
afterEach(function() {
model.$element.remove();
- expect(_(jqCache).size()).toEqual(0);
+ expect(size(jqCache)).toEqual(0);
});
it("should ng-init", function() {
@@ -24,8 +24,6 @@ describe("directives", function(){
it("should ng-eval", function() {
var scope = compile('');
- expect(scope.a).toEqual(0);
- scope.$eval();
expect(scope.a).toEqual(1);
scope.$eval();
expect(scope.a).toEqual(2);
@@ -41,7 +39,6 @@ describe("directives", function(){
it('should ng-bind-template', function() {
var scope = compile('');
- expect(element.text()).toEqual('');
scope.$set('name', 'Misko');
scope.$eval();
expect(element.text()).toEqual('Hello Misko!');
@@ -49,9 +46,6 @@ describe("directives", function(){
it('should ng-bind-attr', function(){
var scope = compile('
');
- expect(element.attr('src')).toEqual(null);
- expect(element.attr('alt')).toEqual(null);
- scope.$eval();
expect(element.attr('src')).toEqual('mysrc');
expect(element.attr('alt')).toEqual('myalt');
});
@@ -126,8 +120,8 @@ describe("directives", function(){
it('should ng-class odd/even', function(){
var scope = compile('