diff options
Diffstat (limited to 'test/CompilerSpec.js')
| -rw-r--r-- | test/CompilerSpec.js | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 1bfc6173..90afbaff 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -13,9 +13,9 @@ describe('compiler', function(){ }; }, - watch: function(expression, element){ + observe: function(expression, element){ return function() { - this.$watch(expression, function(val){ + this.$observe(expression, function(scope, val){ if (val) log += ":" + val; }); @@ -33,10 +33,12 @@ describe('compiler', function(){ }; }); + afterEach(function(){ dealoc(scope); }); + it('should not allow compilation of multiple roots', function(){ expect(function(){ compiler.compile('<div>A</div><span></span>'); @@ -46,6 +48,7 @@ describe('compiler', function(){ } }); + it('should recognize a directive', function(){ var e = jqLite('<div directive="expr" ignore="me"></div>'); directives.directive = function(expression, element){ @@ -63,50 +66,56 @@ describe('compiler', function(){ expect(log).toEqual("found:init"); }); + it('should recurse to children', function(){ scope = compile('<div><span hello="misko"/></div>'); expect(log).toEqual("hello misko"); }); - it('should watch scope', function(){ - scope = compile('<span watch="name"/>'); + + it('should observe scope', function(){ + scope = compile('<span observe="name">'); expect(log).toEqual(""); - scope.$eval(); - scope.$set('name', 'misko'); - scope.$eval(); - scope.$eval(); - scope.$set('name', 'adam'); - scope.$eval(); - scope.$eval(); + scope.$flush(); + scope.name = 'misko'; + scope.$flush(); + scope.$flush(); + scope.name = 'adam'; + scope.$flush(); + scope.$flush(); expect(log).toEqual(":misko:adam"); }); + it('should prevent descend', function(){ directives.stop = function(){ this.descend(false); }; 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.removeAttr("duplicate"); var linker = this.compile(element); return function(marker) { - this.$onEval(function() { + this.$observe(function() { var scope = linker(angular.scope(), noop); marker.after(scope.$element); }); }; }; scope = compile('before<span duplicate="expr">x</span>after'); + scope.$flush(); expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment><span>x</span>after</div>'); - scope.$eval(); + scope.$flush(); expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment><span>x</span><span>x</span>after</div>'); - scope.$eval(); + scope.$flush(); expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment><span>x</span><span>x</span><span>x</span>after</div>'); }); + it('should process markup before directives', function(){ markup.push(function(text, textNode, parentNode) { if (text == 'middle') { @@ -120,6 +129,7 @@ describe('compiler', function(){ expect(log).toEqual("hello middle"); }); + it('should replace widgets', function(){ widgets['NG:BUTTON'] = function(element) { expect(element.hasClass('ng-widget')).toEqual(true); @@ -133,6 +143,7 @@ describe('compiler', function(){ expect(log).toEqual('init'); }); + it('should use the replaced element after calling widget', function(){ widgets['H1'] = function(element) { // HTML elements which are augmented by acting as widgets, should not be marked as so @@ -151,6 +162,7 @@ describe('compiler', function(){ expect(scope.$element.text()).toEqual('3'); }); + it('should allow multiple markups per text element', function(){ markup.push(function(text, textNode, parent){ var index = text.indexOf('---'); @@ -174,6 +186,7 @@ describe('compiler', function(){ expect(sortedHtml(scope.$element)).toEqual('<div>A<hr></hr>B<hr></hr>C<p></p>D</div>'); }); + it('should add class for namespace elements', function(){ scope = compile('<ng:space>abc</ng:space>'); var space = jqLite(scope.$element[0].firstChild); |
