From a80a61839a66d244c8bb14bbe2975746e02516c8 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Sat, 3 Apr 2010 17:04:36 -0700
Subject: injection is now working
---
test/CompilerSpec.js | 62 +++++++++++++++++++---------------------------------
1 file changed, 23 insertions(+), 39 deletions(-)
(limited to 'test/CompilerSpec.js')
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("
" + html + "
");
- var view = compiler.compile(e)(e);
- view.init();
- return view.scope;
+ var e = jqLite("" + html + "
");
+ var scope = compiler.compile(e)(e);
+ scope.$init();
+ return scope;
};
});
it('should recognize a directive', function(){
- var e = element('');
+ var e = jqLite('');
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('');
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('beforexafter');
- expect($(scope.element).html()).toEqual('beforeafter');
- scope.updateView();
- expect($(scope.element).html()).toEqual('beforexafter');
- scope.updateView();
- expect($(scope.element).html()).toEqual('beforexxafter');
- });
-
- it('should allow for exculsive tags which suppress others', function(){
- directives.exclusive = function(){
- return function() {
- log += ('exclusive');
- };
- };
- directives.exclusive.exclusive = true;
-
- compile('');
- expect(log).toEqual('exclusive');
+ expect(sortedHtml(scope.$element)).toEqual('before<#comment>#comment>after
');
+ scope.$eval();
+ expect(sortedHtml(scope.$element)).toEqual('before<#comment>#comment>after
');
+ scope.$eval();
+ expect(sortedHtml(scope.$element)).toEqual('before<#comment>#comment>after
');
});
it('should process markup before directives', function(){
@@ -117,7 +101,7 @@ xdescribe('compiler', function(){
}
});
var scope = compile('beforemiddleafter');
- expect(scope.element.innerHTML).toEqual('beforereplacedafter');
+ expect(scope.$element[0].innerHTML).toEqual('beforereplacedafter');
expect(log).toEqual("hello middle");
});
@@ -129,7 +113,7 @@ xdescribe('compiler', function(){
};
};
var scope = compile('push me');
- expect(scope.element.innerHTML).toEqual('button
');
+ expect(scope.$element[0].innerHTML).toEqual('button
');
expect(log).toEqual('init');
});
--
cgit v1.2.3