Skip to content

Commit 4d152c8

Browse files
committed
WIP: show $compile bug
Transclusion should not be propagated into template directives.
1 parent 5b257a5 commit 4d152c8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/ng/compileSpec.js

+39
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,26 @@ describe('$compile', function() {
15851585

15861586
}));
15871587

1588+
1589+
$compileProvider.directive('transFoo', valueFn({
1590+
template: '<div>' +
1591+
'<div no-trans-bar></div>' +
1592+
'<div ng-transclude>this one should get replaced with content</div>' +
1593+
'<div class="foo" ng-transclude></div>' +
1594+
'</div>',
1595+
transclude: true
1596+
1597+
}));
1598+
1599+
$compileProvider.directive('noTransBar', valueFn({
1600+
template: '<div>' +
1601+
// This ng-transclude is invalid. It should throw an error.
1602+
'<div ng-transclude></div>' +
1603+
'</div>',
1604+
transclude: false
1605+
1606+
}));
1607+
15881608
}));
15891609

15901610
it("should not pick up too many children when transcluding", inject(function($compile, $rootScope) {
@@ -1601,6 +1621,25 @@ describe('$compile', function() {
16011621
dealoc(element);
16021622
}));
16031623

1624+
1625+
iit('should not pass transclusion into a template directive', inject(function($compile, $rootScope) {
1626+
var elm;
1627+
1628+
expect(function() {
1629+
elm = $compile('<div trans-foo>content</div>')($rootScope);
1630+
}).toThrowMinErr('ngTransclude', 'orphan', 'Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found. Element: <div ng-transclude="">');
1631+
1632+
// This is just to demonstrate that ng-transclusion gets propagated.
1633+
if (elm) {
1634+
$rootScope.$digest();
1635+
1636+
var ngTransludeInsideNoTransBarDirective = angular.element(elm[0].querySelector('[no-trans-bar] [ng-transclude]'));
1637+
expect(ngTransludeInsideNoTransBarDirective.text()).toBe('');
1638+
1639+
dealoc(elm);
1640+
}
1641+
}));
1642+
16041643
});
16051644

16061645

0 commit comments

Comments
 (0)