aboutsummaryrefslogtreecommitdiffstats
path: root/test/CompilerSpec.js
diff options
context:
space:
mode:
authorMisko Hevery2010-04-03 17:04:36 -0700
committerMisko Hevery2010-04-03 17:04:36 -0700
commita80a61839a66d244c8bb14bbe2975746e02516c8 (patch)
tree5a7b4d9d3e2a7a15ebf55e068782fbf2aa4ac6bf /test/CompilerSpec.js
parent35ca4fcb9c49e505e28669e951e01ddedb01d7db (diff)
downloadangular.js-a80a61839a66d244c8bb14bbe2975746e02516c8.tar.bz2
injection is now working
Diffstat (limited to 'test/CompilerSpec.js')
-rw-r--r--test/CompilerSpec.js62
1 files changed, 23 insertions, 39 deletions
diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js
index 59b7ab6b..9922070f 100644
--- a/test/CompilerSpec.js
+++ b/test/CompilerSpec.js
@@ -1,8 +1,4 @@
-xdescribe('compiler', function(){
- function element(html) {
- return jQuery(html)[0];
- }
-
+describe('compiler', function(){
var compiler, textMarkup, directives, widgets, compile, log;
beforeEach(function(){
@@ -29,25 +25,25 @@ xdescribe('compiler', function(){
widgets = {};
compiler = new Compiler(textMarkup, attrMarkup, directives, widgets);
compile = function(html){
- var e = element("<div>" + html + "</div>");
- var view = compiler.compile(e)(e);
- view.init();
- return view.scope;
+ var e = jqLite("<div>" + html + "</div>");
+ var scope = compiler.compile(e)(e);
+ scope.$init();
+ return scope;
};
});
it('should recognize a directive', function(){
- var e = element('<div directive="expr" ignore="me"></div>');
+ var e = jqLite('<div directive="expr" ignore="me"></div>');
directives.directive = function(expression, element){
log += "found";
expect(expression).toEqual("expr");
- expect(element[0]).toEqual(e);
+ expect(element).toEqual(e);
return function initFn() {
log += ":init";
};
};
var template = compiler.compile(e);
- var init = template(e).init;
+ var init = template(e).$init;
expect(log).toEqual("found");
init();
expect(log).toEqual("found:init");
@@ -61,13 +57,13 @@ xdescribe('compiler', function(){
it('should watch scope', function(){
var scope = compile('<span watch="name"/>');
expect(log).toEqual("");
- scope.updateView();
- scope.set('name', 'misko');
- scope.updateView();
- scope.updateView();
- scope.set('name', 'adam');
- scope.updateView();
- scope.updateView();
+ scope.$eval();
+ scope.$set('name', 'misko');
+ scope.$eval();
+ scope.$eval();
+ scope.$set('name', 'adam');
+ scope.$eval();
+ scope.$eval();
expect(log).toEqual(":misko:adam");
});
@@ -83,29 +79,17 @@ xdescribe('compiler', function(){
element.removeAttr("duplicate");
var template = this.compile(element);
return function(marker) {
- this.$addEval(function() {
+ this.$onEval(function() {
marker.after(template(element.clone()).element);
});
};
};
var scope = compile('before<span duplicate="expr">x</span>after');
- expect($(scope.element).html()).toEqual('before<!--marker-->after');
- scope.updateView();
- expect($(scope.element).html()).toEqual('before<!--marker--><span>x</span>after');
- scope.updateView();
- expect($(scope.element).html()).toEqual('before<!--marker--><span>x</span><span>x</span>after');
- });
-
- it('should allow for exculsive tags which suppress others', function(){
- directives.exclusive = function(){
- return function() {
- log += ('exclusive');
- };
- };
- directives.exclusive.exclusive = true;
-
- compile('<span hello="misko", exclusive/>');
- expect(log).toEqual('exclusive');
+ expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment>after</div>');
+ scope.$eval();
+ expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment>after</div>');
+ scope.$eval();
+ expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment>after</div>');
});
it('should process markup before directives', function(){
@@ -117,7 +101,7 @@ xdescribe('compiler', function(){
}
});
var scope = compile('before<span>middle</span>after');
- expect(scope.element.innerHTML).toEqual('before<span hello="middle">replaced</span>after');
+ expect(scope.$element[0].innerHTML).toEqual('before<span hello="middle">replaced</span>after');
expect(log).toEqual("hello middle");
});
@@ -129,7 +113,7 @@ xdescribe('compiler', function(){
};
};
var scope = compile('<ng:button>push me</ng:button>');
- expect(scope.element.innerHTML).toEqual('<div>button</div>');
+ expect(scope.$element[0].innerHTML).toEqual('<div>button</div>');
expect(log).toEqual('init');
});