Skip to content

Commit

Permalink
test($compile): nested transcludes are passing down tree
Browse files Browse the repository at this point in the history
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
  • Loading branch information
petebacondarwin committed May 15, 2014
1 parent c96c674 commit fdde639
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,96 @@ describe('$compile', function() {
}
));

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

module(function($compileProvider) {
// This directive transcludes its contents and hopes to use the
// transcluded content in its template
$compileProvider.directive('transTest', valueFn({
templateUrl: 'transTestTemplate',
transclude: true
}));
});

inject(function($compile, $rootScope, $templateCache) {
// This is the template for the trans-test directive, it contains an
// ng-if, which also uses transclusion, which basically blocks the inner
// trans-test directive from receiving any transcluded content
$templateCache.put('transTestTemplate',
' <div ng-if="true">'+
' <div ng-transclude></div>'+
'</div>');

element = $compile('<div trans-test>transcluded content</div>')($rootScope);

// The ngTransclude:orphan error gets thrown when the digest occurs since this
// is when the ngTransclude directive tries to use the transcluded function.
$rootScope.$digest();

expect(element.text().trim()).toEqual('transcluded content');
});
});


describe('nested transcludes', function() {

beforeEach(module(function($compileProvider) {

$compileProvider.directive('noop', valueFn({}));

$compileProvider.directive('t1', valueFn({
template: '<div noop><div t2><div ng-transclude></div></div></div>',
transclude: true
}));

$compileProvider.directive('t2', valueFn({
template: '<div ng-transclude></div>',
transclude: true
}));

$compileProvider.directive('t1a', valueFn({
templateUrl: 't1a',
transclude: true
}));

$compileProvider.directive('t1b', valueFn({
templateUrl: 't1b',
transclude: true
}));

$compileProvider.directive('t2a', valueFn({
templateUrl: 't2a',
transclude: true
}));
}));

beforeEach(inject(function($templateCache) {
$templateCache.put('t1a', '<div noop><div t2><div ng-transclude></div></div></div>');
$templateCache.put('t1b', '<div noop><div t2a><div ng-transclude></div></div></div>');
$templateCache.put('t2a', '<div ng-transclude></div>');
}));


it('should allow nested transclude directives with sync templates', inject(function($compile, $rootScope) {
element = $compile('<div t1>transcluded content</div>')($rootScope);
$rootScope.$digest();
expect(element.text().trim()).toEqual('transcluded content');
}));

it('should allow nested transclude directives with sync templates', inject(function($compile, $rootScope) {
element = $compile('<div t1a>transcluded content</div>')($rootScope);
$rootScope.$digest();
expect(element.text().trim()).toEqual('transcluded content');
}));

it('should allow nested transclude directives with sync templates', inject(function($compile, $rootScope) {
element = $compile('<div t1b>transcluded content</div>')($rootScope);
$rootScope.$digest();
expect(element.text().trim()).toEqual('transcluded content');
}));
});



describe('nested transcludes', function() {

Expand Down

0 comments on commit fdde639

Please sign in to comment.