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/CompilerSpec.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'test/CompilerSpec.js') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 9f02262d..3ea2e473 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -36,7 +36,7 @@ describe('compiler', function(){ }); it('should recognize a directive', function(){ - var e = element('
'); + var e = element('
'); directives.directive = function(expression, element){ log += "found"; expect(expression).toEqual("expr"); @@ -53,12 +53,12 @@ describe('compiler', function(){ }); it('should recurse to children', function(){ - var scope = compile('
'); + var scope = compile('
'); expect(log).toEqual("hello misko"); }); it('should watch scope', function(){ - var scope = compile(''); + var scope = compile(''); expect(log).toEqual(""); scope.updateView(); scope.set('name', 'misko'); @@ -70,24 +70,24 @@ describe('compiler', function(){ expect(log).toEqual(":misko:adam"); }); - it('should prevent recursion', function(){ - directives.stop = function(){ return false; }; - var scope = compile(''); + it('should prevent descend', function(){ + directives.stop = function(){ this.descend(false); }; + var scope = compile(''); expect(log).toEqual("hello misko"); }); it('should allow creation of templates', function(){ directives.duplicate = function(expr, element){ element.replaceWith(document.createComment("marker")); - element.removeAttribute("ng-duplicate"); + element.removeAttr("duplicate"); var template = this.compile(element); return function(marker) { - this.$eval(function() { + this.$addEval(function() { marker.after(template(element.clone()).element); }); }; }; - var scope = compile('beforexafter'); + var scope = compile('beforexafter'); expect($(scope.element).html()).toEqual('beforeafter'); scope.updateView(); expect($(scope.element).html()).toEqual('beforexafter'); @@ -103,7 +103,7 @@ describe('compiler', function(){ }; directives.exclusive.exclusive = true; - compile(''); + compile(''); expect(log).toEqual('exclusive'); }); @@ -111,24 +111,25 @@ describe('compiler', function(){ markup.push(function(text, textNode, parentNode) { if (text == 'middle') { expect(textNode.text()).toEqual(text); - parentNode.attr('ng-hello', text); + parentNode.attr('hello', text); textNode.text('replaced'); } }); var scope = compile('beforemiddleafter'); - expect(scope.element.innerHTML).toEqual('beforereplacedafter'); + expect(scope.element.innerHTML).toEqual('beforereplacedafter'); expect(log).toEqual("hello middle"); }); - xit('should replace widgets', function(){ - widgets.button = function(element) { - element.parentNode.replaceChild(button, element); + it('should replace widgets', function(){ + widgets['NG:BUTTON'] = function(element) { + element.replaceWith('
button
', element); return function(element) { log += 'init'; }; }; var scope = compile('push me'); - expect(scope.element.innerHTML).toEqual('beforereplacedafter'); + expect(scope.element.innerHTML).toEqual('
button
'); + expect(log).toEqual('init'); }); }); -- cgit v1.2.3