From 7e86eacf301934335c22908ec6dbd1a083d88fab Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 3 Apr 2012 14:15:42 -0700 Subject: fix($compile): relax the restriction that directives can not add siblings Relax the restriction that directives can not add siblings --- test/ng/compilerSpec.js | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'test/ng/compilerSpec.js') diff --git a/test/ng/compilerSpec.js b/test/ng/compilerSpec.js index 55479396..f9d8d301 100644 --- a/test/ng/compilerSpec.js +++ b/test/ng/compilerSpec.js @@ -242,16 +242,39 @@ describe('$compile', function() { }); - it('should prevent changing of structure', inject( - function($compile, $rootScope){ - element = jqLite("
"); - var linkFn = $compile(element); - element.append("
"); - expect(function() { - linkFn($rootScope); - }).toThrow('Template changed structure!'); - } - )); + it('should allow changing the template structure after the current node', function() { + module(function($compileProvider){ + $compileProvider.directive('after', valueFn({ + compile: function(element) { + element.after('B'); + } + })); + }); + inject(function($compile, $rootScope, log){ + element = jqLite("
A
"); + $compile(element)($rootScope); + expect(element.text()).toBe('AB'); + expect(log).toEqual('LOG'); + }); + }); + + + it('should allow changing the template structure after the current node inside ngRepeat', function() { + module(function($compileProvider){ + $compileProvider.directive('after', valueFn({ + compile: function(element) { + element.after('B'); + } + })); + }); + inject(function($compile, $rootScope, log){ + element = jqLite('
A
'); + $compile(element)($rootScope); + $rootScope.$digest(); + expect(element.text()).toBe('ABAB'); + expect(log).toEqual('LOG; LOG'); + }); + }); }); describe('compiler control', function() { -- cgit v1.2.3