Skip to content

Commit 5a5327c

Browse files
test($compile): top level nested transcludes are passing down tree
If you have two directives that both expect to receive transcluded content the outer directive works but the inner directive never receives a transclusion function, only if the first transclude directive is not the first directive found in compilation. See angular#7240
1 parent 7e56eda commit 5a5327c

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

Diff for: test/ng/compileSpec.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,36 @@ describe('$compile', function() {
14451445

14461446
iit('should pass the transcluded content through to ng-transclude', function() {
14471447

1448+
module(function($compileProvider) {
1449+
// This directive transcludes its contents and hopes to use the
1450+
// transcluded content in its template
1451+
$compileProvider.directive('transTest', valueFn({
1452+
templateUrl: 'transTestTemplate',
1453+
transclude: true
1454+
}));
1455+
});
1456+
1457+
inject(function($compile, $rootScope, $templateCache) {
1458+
// This is the template for the trans-test directive, it contains an
1459+
// ng-if, which also uses transclusion, which basically blocks the inner
1460+
// trans-test directive from receiving any transcluded content
1461+
$templateCache.put('transTestTemplate',
1462+
' <div ng-if="true">'+
1463+
' <div ng-transclude></div>'+
1464+
'</div>');
1465+
1466+
element = $compile('<div trans-test>transcluded content</div>')($rootScope);
1467+
1468+
// The ngTransclude:orphan error gets thrown when the digest occurs since this
1469+
// is when the ngTransclude directive tries to use the transcluded function.
1470+
$rootScope.$digest();
1471+
1472+
expect(element.text().trim()).toEqual('transcluded content');
1473+
});
1474+
});
1475+
1476+
iit('should pass the transcluded content through to ng-transclude, when not the highest directive', function() {
1477+
14481478
module(function($compileProvider) {
14491479
// This directive transcludes its contents and hopes to use the
14501480
// transcluded content in its template
@@ -1467,7 +1497,6 @@ describe('$compile', function() {
14671497
'<div noop>'+
14681498
' <div ng-if="true">'+
14691499
' <div ng-transclude></div>'+
1470-
' _this should be removed_' +
14711500
' </div>'+
14721501
'</div>');
14731502

@@ -1481,7 +1510,6 @@ describe('$compile', function() {
14811510
});
14821511
});
14831512

1484-
14851513
it("should fail if replacing and template doesn't have a single root element", function() {
14861514
module(function($exceptionHandlerProvider) {
14871515
$exceptionHandlerProvider.mode('log');

0 commit comments

Comments
 (0)