Skip to content

Commit fdde639

Browse files
test($compile): 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 c96c674 commit fdde639

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

test/ng/compileSpec.js

+90
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,96 @@ describe('$compile', function() {
14961496
}
14971497
));
14981498

1499+
it('should pass the transcluded content through to ng-transclude', function() {
1500+
1501+
module(function($compileProvider) {
1502+
// This directive transcludes its contents and hopes to use the
1503+
// transcluded content in its template
1504+
$compileProvider.directive('transTest', valueFn({
1505+
templateUrl: 'transTestTemplate',
1506+
transclude: true
1507+
}));
1508+
});
1509+
1510+
inject(function($compile, $rootScope, $templateCache) {
1511+
// This is the template for the trans-test directive, it contains an
1512+
// ng-if, which also uses transclusion, which basically blocks the inner
1513+
// trans-test directive from receiving any transcluded content
1514+
$templateCache.put('transTestTemplate',
1515+
' <div ng-if="true">'+
1516+
' <div ng-transclude></div>'+
1517+
'</div>');
1518+
1519+
element = $compile('<div trans-test>transcluded content</div>')($rootScope);
1520+
1521+
// The ngTransclude:orphan error gets thrown when the digest occurs since this
1522+
// is when the ngTransclude directive tries to use the transcluded function.
1523+
$rootScope.$digest();
1524+
1525+
expect(element.text().trim()).toEqual('transcluded content');
1526+
});
1527+
});
1528+
1529+
1530+
describe('nested transcludes', function() {
1531+
1532+
beforeEach(module(function($compileProvider) {
1533+
1534+
$compileProvider.directive('noop', valueFn({}));
1535+
1536+
$compileProvider.directive('t1', valueFn({
1537+
template: '<div noop><div t2><div ng-transclude></div></div></div>',
1538+
transclude: true
1539+
}));
1540+
1541+
$compileProvider.directive('t2', valueFn({
1542+
template: '<div ng-transclude></div>',
1543+
transclude: true
1544+
}));
1545+
1546+
$compileProvider.directive('t1a', valueFn({
1547+
templateUrl: 't1a',
1548+
transclude: true
1549+
}));
1550+
1551+
$compileProvider.directive('t1b', valueFn({
1552+
templateUrl: 't1b',
1553+
transclude: true
1554+
}));
1555+
1556+
$compileProvider.directive('t2a', valueFn({
1557+
templateUrl: 't2a',
1558+
transclude: true
1559+
}));
1560+
}));
1561+
1562+
beforeEach(inject(function($templateCache) {
1563+
$templateCache.put('t1a', '<div noop><div t2><div ng-transclude></div></div></div>');
1564+
$templateCache.put('t1b', '<div noop><div t2a><div ng-transclude></div></div></div>');
1565+
$templateCache.put('t2a', '<div ng-transclude></div>');
1566+
}));
1567+
1568+
1569+
it('should allow nested transclude directives with sync templates', inject(function($compile, $rootScope) {
1570+
element = $compile('<div t1>transcluded content</div>')($rootScope);
1571+
$rootScope.$digest();
1572+
expect(element.text().trim()).toEqual('transcluded content');
1573+
}));
1574+
1575+
it('should allow nested transclude directives with sync templates', inject(function($compile, $rootScope) {
1576+
element = $compile('<div t1a>transcluded content</div>')($rootScope);
1577+
$rootScope.$digest();
1578+
expect(element.text().trim()).toEqual('transcluded content');
1579+
}));
1580+
1581+
it('should allow nested transclude directives with sync templates', inject(function($compile, $rootScope) {
1582+
element = $compile('<div t1b>transcluded content</div>')($rootScope);
1583+
$rootScope.$digest();
1584+
expect(element.text().trim()).toEqual('transcluded content');
1585+
}));
1586+
});
1587+
1588+
14991589

15001590
describe('nested transcludes', function() {
15011591

0 commit comments

Comments
 (0)