Skip to content

Commit

Permalink
test($compile): top level 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 7, 2014
1 parent 7e56eda commit 7599625
Showing 1 changed file with 91 additions and 1 deletion.
92 changes: 91 additions & 1 deletion test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,59 @@ describe('$compile', function() {

iit('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');
});
});


iit('nested ngIfs should transclude correctly', function() {

module(function($compileProvider) {
// This directive does nothing except to put a directive in the compile
// element ancestors list between the root $compile node and the trans-test
// directives' element
$compileProvider.directive('noop', valueFn({}));
});

inject(function($compile, $rootScope) {
element = $compile('<div noop><div ng-if="true">outer<div ng-if="true">inner</div></div></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('outerinner');
});
});

iit('should pass the transcluded content through to ng-transclude, ' +
'when not the highest directive' +
'and with external template', function() {

module(function($compileProvider) {
// This directive transcludes its contents and hopes to use the
// transcluded content in its template
Expand All @@ -1467,7 +1520,6 @@ describe('$compile', function() {
'<div noop>'+
' <div ng-if="true">'+
' <div ng-transclude></div>'+
' _this should be removed_' +
' </div>'+
'</div>');

Expand All @@ -1481,6 +1533,44 @@ describe('$compile', function() {
});
});

iit('should pass the transcluded content through to ng-transclude, ' +
'when not the highest directive' +
'and with inline template', function() {

module(function($compileProvider) {
// This directive transcludes its contents and hopes to use the
// transcluded content in its template
$compileProvider.directive('transTest', valueFn({
template:
// 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
'<div noop>'+
' <div ng-if="true">'+
' <div ng-transclude></div>'+
' </div>'+
'</div>',
transclude: true
}));

// This directive does nothing except to put a directive in the compile
// element ancestors list between the root $compile node and the trans-test
// directives' element
$compileProvider.directive('noop', valueFn({}));
});

inject(function($compile, $rootScope, $templateCache) {

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');
});
});


it("should fail if replacing and template doesn't have a single root element", function() {
module(function($exceptionHandlerProvider) {
Expand Down

0 comments on commit 7599625

Please sign in to comment.