@@ -7966,7 +7966,7 @@ describe('$compile', function() {
7966
7966
} ) ;
7967
7967
7968
7968
7969
- it ( 'should provide the elements marked with matching transclude elements as additional transclude functions on the $slots property ' , function ( ) {
7969
+ it ( 'should return true from `isSlotFilled(slotName) for slots that have content in the transclusion ' , function ( ) {
7970
7970
var capturedTranscludeFn ;
7971
7971
module ( function ( ) {
7972
7972
directive ( 'minionComponent' , function ( ) {
@@ -7975,7 +7975,7 @@ describe('$compile', function() {
7975
7975
scope : { } ,
7976
7976
transclude : {
7977
7977
minionSlot : 'minion' ,
7978
- bossSlot : 'boss'
7978
+ bossSlot : '? boss'
7979
7979
} ,
7980
7980
template :
7981
7981
'<div class="boss" ng-transclude="bossSlot"></div>' +
@@ -7993,36 +7993,49 @@ describe('$compile', function() {
7993
7993
' <minion>stuart</minion>' +
7994
7994
' <minion>bob</minion>' +
7995
7995
' <span>dorothy</span>' +
7996
- ' <boss>gru</boss>' +
7997
7996
'</minion-component>' ) ( $rootScope ) ;
7998
7997
$rootScope . $apply ( ) ;
7999
7998
8000
- var minionTranscludeFn = capturedTranscludeFn . $slots [ 'minionSlot' ] ;
8001
- var minions = minionTranscludeFn ( ) ;
8002
- expect ( minions [ 0 ] . outerHTML ) . toEqual ( '<minion class="ng-scope">stuart</minion>' ) ;
8003
- expect ( minions [ 1 ] . outerHTML ) . toEqual ( '<minion class="ng-scope">bob</minion>' ) ;
8004
-
8005
- var scope = element . scope ( ) ;
8006
-
8007
- var minionScope = jqLite ( minions [ 0 ] ) . scope ( ) ;
8008
- expect ( minionScope . $parent ) . toBe ( scope ) ;
8009
-
8010
- var bossTranscludeFn = capturedTranscludeFn . $slots [ 'bossSlot' ] ;
8011
- var boss = bossTranscludeFn ( ) ;
8012
- expect ( boss [ 0 ] . outerHTML ) . toEqual ( '<boss class="ng-scope">gru</boss>' ) ;
7999
+ var hasMinions = capturedTranscludeFn . isSlotFilled ( 'minionSlot' ) ;
8000
+ var hasBosses = capturedTranscludeFn . isSlotFilled ( 'bossSlot' ) ;
8013
8001
8014
- var bossScope = jqLite ( boss [ 0 ] ) . scope ( ) ;
8015
- expect ( bossScope . $parent ) . toBe ( scope ) ;
8016
-
8017
- expect ( bossScope ) . not . toBe ( minionScope ) ;
8002
+ expect ( hasMinions ) . toBe ( true ) ;
8003
+ expect ( hasBosses ) . toBe ( false ) ;
8004
+ } ) ;
8005
+ } ) ;
8018
8006
8019
- dealoc ( boss ) ;
8020
- dealoc ( minions ) ;
8007
+ it ( 'should not overwrite the contents of an `ng-transclude` element, if the matching optional slot is not filled' , function ( ) {
8008
+ module ( function ( ) {
8009
+ directive ( 'minionComponent' , function ( ) {
8010
+ return {
8011
+ restrict : 'E' ,
8012
+ scope : { } ,
8013
+ transclude : {
8014
+ minionSlot : 'minion' ,
8015
+ bossSlot : '?boss'
8016
+ } ,
8017
+ template :
8018
+ '<div class="boss" ng-transclude="bossSlot">default boss content</div>' +
8019
+ '<div class="minion" ng-transclude="minionSlot">default minion content</div>' +
8020
+ '<div class="other" ng-transclude>default content</div>'
8021
+ } ;
8022
+ } ) ;
8023
+ } ) ;
8024
+ inject ( function ( $rootScope , $compile ) {
8025
+ element = $compile (
8026
+ '<minion-component>' +
8027
+ '<minion>stuart</minion>' +
8028
+ '<span>dorothy</span>' +
8029
+ '<minion>kevin</minion>' +
8030
+ '</minion-component>' ) ( $rootScope ) ;
8031
+ $rootScope . $apply ( ) ;
8032
+ expect ( element . children ( ) . eq ( 0 ) . text ( ) ) . toEqual ( 'default boss content' ) ;
8033
+ expect ( element . children ( ) . eq ( 1 ) . text ( ) ) . toEqual ( 'stuartkevin' ) ;
8034
+ expect ( element . children ( ) . eq ( 2 ) . text ( ) ) . toEqual ( 'dorothy' ) ;
8021
8035
} ) ;
8022
8036
} ) ;
8023
8037
8024
- it ( 'should set unfilled optional transclude slots to `null` in the $transclude.$slots property' , function ( ) {
8025
- var capturedTranscludeFn ;
8038
+ it ( 'should not overwrite the contents of an `ng-transclude` element, if the matching optional slot is not filled' , function ( ) {
8026
8039
module ( function ( ) {
8027
8040
directive ( 'minionComponent' , function ( ) {
8028
8041
return {
@@ -8032,9 +8045,10 @@ describe('$compile', function() {
8032
8045
minionSlot : 'minion' ,
8033
8046
bossSlot : '?boss'
8034
8047
} ,
8035
- link : function ( s , e , a , c , transcludeFn ) {
8036
- capturedTranscludeFn = transcludeFn ;
8037
- }
8048
+ template :
8049
+ '<div class="boss" ng-transclude="bossSlot">default boss content</div>' +
8050
+ '<div class="minion" ng-transclude="minionSlot">default minion content</div>' +
8051
+ '<div class="other" ng-transclude>default content</div>'
8038
8052
} ;
8039
8053
} ) ;
8040
8054
} ) ;
@@ -8043,9 +8057,12 @@ describe('$compile', function() {
8043
8057
'<minion-component>' +
8044
8058
'<minion>stuart</minion>' +
8045
8059
'<span>dorothy</span>' +
8060
+ '<minion>kevin</minion>' +
8046
8061
'</minion-component>' ) ( $rootScope ) ;
8047
- expect ( capturedTranscludeFn . $slots . minionSlot ) . toEqual ( jasmine . any ( Function ) ) ;
8048
- expect ( capturedTranscludeFn . $slots . bossSlot ) . toBe ( null ) ;
8062
+ $rootScope . $apply ( ) ;
8063
+ expect ( element . children ( ) . eq ( 0 ) . text ( ) ) . toEqual ( 'default boss content' ) ;
8064
+ expect ( element . children ( ) . eq ( 1 ) . text ( ) ) . toEqual ( 'stuartkevin' ) ;
8065
+ expect ( element . children ( ) . eq ( 2 ) . text ( ) ) . toEqual ( 'dorothy' ) ;
8049
8066
} ) ;
8050
8067
} ) ;
8051
8068
} ) ;
0 commit comments