From 97c7a4e3791d7cb05c3317cc5f0c49ab93810bf6 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 5 Nov 2013 15:50:53 -0800 Subject: fix($compile): replaced element has isolate scope --- test/ng/compileSpec.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 2b6b235f..75c111d7 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -2450,7 +2450,7 @@ describe('$compile', function() { it('should require controller of an isolate directive from a non-isolate directive on the ' + - 'same element', function() { + 'same element', function() { var IsolateController = function() {}; var isolateDirControllerInNonIsolateDirective; @@ -2480,6 +2480,79 @@ describe('$compile', function() { }); + it('should share isolate scope with replaced directives', function() { + var normalScope; + var isolateScope; + + module(function() { + directive('isolate', function() { + return { + replace: true, + scope: {}, + template: '{{name}}', + link: function(s) { + isolateScope = s; + } + }; + }); + directive('nonIsolate', function() { + return { + link: function(s) { + normalScope = s; + } + }; + }); + }); + + inject(function($compile, $rootScope) { + element = $compile('
')($rootScope); + + expect(normalScope).toBe($rootScope); + expect(normalScope.name).toEqual(undefined); + expect(isolateScope.name).toEqual('WORKS'); + $rootScope.$digest(); + expect(element.text()).toEqual('WORKS'); + }); + }); + + + it('should share isolate scope with replaced directives', function() { + var normalScope; + var isolateScope; + + module(function() { + directive('isolate', function() { + return { + replace: true, + scope: {}, + templateUrl: 'main.html', + link: function(s) { + isolateScope = s; + } + }; + }); + directive('nonIsolate', function() { + return { + link: function(s) { + normalScope = s; + } + }; + }); + }); + + inject(function($compile, $rootScope, $templateCache) { + $templateCache.put('main.html', '{{name}}'); + element = $compile('
')($rootScope); + $rootScope.$apply(); + + expect(normalScope).toBe($rootScope); + expect(normalScope.name).toEqual(undefined); + expect(isolateScope.name).toEqual('WORKS'); + expect(element.text()).toEqual('WORKS'); + }); + }); + + it('should require controller of a non-isolate directive from an isolate directive on the ' + 'same element', function() { var NonIsolateController = function() {}; -- cgit v1.2.3