diff options
Diffstat (limited to 'test/CompilerSpec.js')
| -rw-r--r-- | test/CompilerSpec.js | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 8487b139..59b7ab6b 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -3,7 +3,7 @@ xdescribe('compiler', function(){ return jQuery(html)[0]; } - var compiler, markup, directives, widgets, compile, log; + var compiler, textMarkup, directives, widgets, compile, log; beforeEach(function(){ log = ""; @@ -24,9 +24,10 @@ xdescribe('compiler', function(){ } }; - markup = []; + textMarkup = []; + attrMarkup = []; widgets = {}; - compiler = new Compiler(markup, directives, widgets); + compiler = new Compiler(textMarkup, attrMarkup, directives, widgets); compile = function(html){ var e = element("<div>" + html + "</div>"); var view = compiler.compile(e)(e); @@ -36,11 +37,11 @@ xdescribe('compiler', function(){ }); it('should recognize a directive', function(){ - var e = element('<div ng-directive="expr" ignore="me"></div>'); + var e = element('<div directive="expr" ignore="me"></div>'); directives.directive = function(expression, element){ log += "found"; expect(expression).toEqual("expr"); - expect(element.element).toEqual(e); + expect(element[0]).toEqual(e); return function initFn() { log += ":init"; }; @@ -53,12 +54,12 @@ xdescribe('compiler', function(){ }); it('should recurse to children', function(){ - var scope = compile('<div><span ng-hello="misko"/></div>'); + var scope = compile('<div><span hello="misko"/></div>'); expect(log).toEqual("hello misko"); }); it('should watch scope', function(){ - var scope = compile('<span ng-watch="name"/>'); + var scope = compile('<span watch="name"/>'); expect(log).toEqual(""); scope.updateView(); scope.set('name', 'misko'); @@ -70,26 +71,24 @@ xdescribe('compiler', function(){ expect(log).toEqual(":misko:adam"); }); - it('should prevent recursion', function(){ - directives.stop = function(){ return false; }; - var scope = compile('<span ng-hello="misko" ng-stop="true"><span ng-hello="adam"/></span>'); + it('should prevent descend', function(){ + directives.stop = function(){ this.descend(false); }; + var scope = compile('<span hello="misko" stop="true"><span hello="adam"/></span>'); 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() { - dump("A"); + this.$addEval(function() { marker.after(template(element.clone()).element); - dump("B"); }); }; }; - var scope = compile('before<span ng-duplicate="expr">x</span>after'); + 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'); @@ -105,32 +104,33 @@ xdescribe('compiler', function(){ }; directives.exclusive.exclusive = true; - compile('<span ng-hello="misko", ng-exclusive/>'); + compile('<span hello="misko", exclusive/>'); expect(log).toEqual('exclusive'); }); it('should process markup before directives', function(){ - markup.push(function(text, textNode, parentNode) { + textMarkup.push(function(text, textNode, parentNode) { if (text == 'middle') { expect(textNode.text()).toEqual(text); - parentNode.attr('ng-hello', text); - textNode.nodeValue = 'replaced'; + parentNode.attr('hello', text); + textNode.text('replaced'); } }); var scope = compile('before<span>middle</span>after'); - expect(scope.element.innerHTML).toEqual('before<span ng-hello="middle">replaced</span>after'); + expect(scope.element.innerHTML).toEqual('before<span hello="middle">replaced</span>after'); expect(log).toEqual("hello middle"); }); it('should replace widgets', function(){ - widgets.button = function(element) { - element.parentNode.replaceChild(button, element); + widgets['NG:BUTTON'] = function(element) { + element.replaceWith('<div>button</div>', element); return function(element) { log += 'init'; }; }; var scope = compile('<ng:button>push me</ng:button>'); - expect(scope.element.innerHTML).toEqual('before<span ng-hello="middle">replaced</span>after'); + expect(scope.element.innerHTML).toEqual('<div>button</div>'); + expect(log).toEqual('init'); }); }); |
