diff options
author | Misko Hevery | 2010-03-18 17:12:38 -0700 |
---|---|---|
committer | Misko Hevery | 2010-03-18 17:12:38 -0700 |
commit | be3c7a66709952ffd21e4e59268ba6370e09d7ed (patch) | |
tree | 42c838e52cb88bde804289be2254682e502599dc /test | |
parent | 79f868cbca4a14030447e321ba59348cf1eb8a02 (diff) | |
download | angular.js-be3c7a66709952ffd21e4e59268ba6370e09d7ed.tar.bz2 |
cleanup work
Diffstat (limited to 'test')
-rw-r--r-- | test/CompilerSpec.js | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 4033ebdc..2c156cc4 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -3,7 +3,7 @@ describe('compiler', function(){ return jQuery(html)[0]; } - var compiler, markup, directives, compile, log; + var compiler, markup, directives, widgets, compile, log; beforeEach(function(){ log = ""; @@ -25,7 +25,8 @@ describe('compiler', function(){ }; markup = []; - compiler = new Compiler(markup, directives); + widgets = {}; + compiler = new Compiler(markup, directives, widgets); compile = function(html){ var e = element("<div>" + html + "</div>"); var view = compiler.compile(e)(e); @@ -39,7 +40,7 @@ describe('compiler', function(){ directives.directive = function(expression, element){ log += "found"; expect(expression).toEqual("expr"); - expect(element).toEqual(e); + expect(element.element).toEqual(e); return function initFn() { log += ":init"; }; @@ -78,17 +79,15 @@ describe('compiler', function(){ it('should allow creation of templates', function(){ directives.duplicate = function(expr, element){ var template, - marker = document.createComment("marker"), - parentNode = element.parentNode; - parentNode.insertBefore(marker, element); - parentNode.removeChild(element); + marker = document.createComment("marker"); + element.replaceWith(marker); element.removeAttribute("ng-duplicate"); template = this.compile(element); return function(marker) { var parentNode = marker.parentNode; this.$eval(function() { parentNode.insertBefore( - template(element.cloneNode(true)).element, + template(element.clone()).element, marker.nextSibling); }); }; @@ -116,8 +115,8 @@ describe('compiler', function(){ it('should process markup before directives', function(){ markup.push(function(text, textNode, parentNode) { if (text == 'middle') { - expect(textNode.nodeValue).toEqual(text); - parentNode.setAttribute('ng-hello', text); + expect(textNode.text()).toEqual(text); + parentNode.attr('ng-hello', text); textNode.nodeValue = 'replaced'; } }); @@ -125,4 +124,15 @@ describe('compiler', function(){ expect(scope.element.innerHTML).toEqual('before<span ng-hello="middle">replaced</span>after'); expect(log).toEqual("hello middle"); }); + + it('should replace widgets', function(){ + widgets.button = function(element) { + element.parentNode.replaceChild(button, 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'); + }); }); |