@@ -7971,16 +7971,14 @@ describe('$compile', function() {
7971
7971
7972
7972
7973
7973
it ( 'should not compile the fallback content if transcluded content is provided' , function ( ) {
7974
- var contentsDidLink = false ;
7974
+ var linkSpy = jasmine . createSpy ( 'postlink' ) ;
7975
7975
7976
7976
module ( function ( ) {
7977
7977
directive ( 'inner' , function ( ) {
7978
7978
return {
7979
7979
restrict : 'E' ,
7980
7980
template : 'old stuff! ' ,
7981
- link : function ( ) {
7982
- contentsDidLink = true ;
7983
- }
7981
+ link : linkSpy
7984
7982
} ;
7985
7983
} ) ;
7986
7984
@@ -7995,21 +7993,19 @@ describe('$compile', function() {
7995
7993
element = $compile ( '<div trans>unicorn!</div>' ) ( $rootScope ) ;
7996
7994
$rootScope . $apply ( ) ;
7997
7995
expect ( sortedHtml ( element . html ( ) ) ) . toEqual ( '<div ng-transclude="">unicorn!</div>' ) ;
7998
- expect ( contentsDidLink ) . toBe ( false ) ;
7996
+ expect ( linkSpy ) . not . toHaveBeenCalled ( ) ;
7999
7997
} ) ;
8000
7998
} ) ;
8001
7999
8002
8000
it ( 'should compile and link the fallback content if no transcluded content is provided' , function ( ) {
8003
- var contentsDidLink = false ;
8001
+ var linkSpy = jasmine . createSpy ( 'postlink' ) ;
8004
8002
8005
8003
module ( function ( ) {
8006
8004
directive ( 'inner' , function ( ) {
8007
8005
return {
8008
8006
restrict : 'E' ,
8009
8007
template : 'old stuff! ' ,
8010
- link : function ( ) {
8011
- contentsDidLink = true ;
8012
- }
8008
+ link : linkSpy
8013
8009
} ;
8014
8010
} ) ;
8015
8011
@@ -8024,7 +8020,50 @@ describe('$compile', function() {
8024
8020
element = $compile ( '<div trans></div>' ) ( $rootScope ) ;
8025
8021
$rootScope . $apply ( ) ;
8026
8022
expect ( sortedHtml ( element . html ( ) ) ) . toEqual ( '<div ng-transclude=""><inner>old stuff! </inner></div>' ) ;
8027
- expect ( contentsDidLink ) . toBe ( true ) ;
8023
+ expect ( linkSpy ) . toHaveBeenCalled ( ) ;
8024
+ } ) ;
8025
+ } ) ;
8026
+
8027
+ it ( 'should compile and link the fallback content if an optional transclusion slot is not provided' , function ( ) {
8028
+ var linkSpy = jasmine . createSpy ( 'postlink' ) ;
8029
+
8030
+ module ( function ( ) {
8031
+ directive ( 'inner' , function ( ) {
8032
+ return {
8033
+ restrict : 'E' ,
8034
+ template : 'old stuff! ' ,
8035
+ link : linkSpy
8036
+ } ;
8037
+ } ) ;
8038
+
8039
+ directive ( 'trans' , function ( ) {
8040
+ return {
8041
+ transclude : { optionalSlot : '?optional' } ,
8042
+ template : '<div ng-transclude="optionalSlot"><inner></inner></div>'
8043
+ } ;
8044
+ } ) ;
8045
+ } ) ;
8046
+ inject ( function ( log , $rootScope , $compile ) {
8047
+ element = $compile ( '<div trans></div>' ) ( $rootScope ) ;
8048
+ $rootScope . $apply ( ) ;
8049
+ expect ( sortedHtml ( element . html ( ) ) ) . toEqual ( '<div ng-transclude="optionalSlot"><inner>old stuff! </inner></div>' ) ;
8050
+ expect ( linkSpy ) . toHaveBeenCalled ( ) ;
8051
+ } ) ;
8052
+ } ) ;
8053
+
8054
+ it ( 'should cope if there is neither transcluded content nor fallback content' , function ( ) {
8055
+ module ( function ( ) {
8056
+ directive ( 'trans' , function ( ) {
8057
+ return {
8058
+ transclude : true ,
8059
+ template : '<div ng-transclude></div>'
8060
+ } ;
8061
+ } ) ;
8062
+ } ) ;
8063
+ inject ( function ( $rootScope , $compile ) {
8064
+ element = $compile ( '<div trans></div>' ) ( $rootScope ) ;
8065
+ $rootScope . $apply ( ) ;
8066
+ expect ( sortedHtml ( element . html ( ) ) ) . toEqual ( '<div ng-transclude=""></div>' ) ;
8028
8067
} ) ;
8029
8068
} ) ;
8030
8069
@@ -9824,37 +9863,6 @@ describe('$compile', function() {
9824
9863
expect ( element . children ( ) . eq ( 2 ) . text ( ) ) . toEqual ( 'dorothy' ) ;
9825
9864
} ) ;
9826
9865
} ) ;
9827
-
9828
- it ( 'should not overwrite the contents of an `ng-transclude` element, if the matching optional slot is not filled' , function ( ) {
9829
- module ( function ( ) {
9830
- directive ( 'minionComponent' , function ( ) {
9831
- return {
9832
- restrict : 'E' ,
9833
- scope : { } ,
9834
- transclude : {
9835
- minionSlot : 'minion' ,
9836
- bossSlot : '?boss'
9837
- } ,
9838
- template :
9839
- '<div class="boss" ng-transclude="bossSlot">default boss content</div>' +
9840
- '<div class="minion" ng-transclude="minionSlot">default minion content</div>' +
9841
- '<div class="other" ng-transclude>default content</div>'
9842
- } ;
9843
- } ) ;
9844
- } ) ;
9845
- inject ( function ( $rootScope , $compile ) {
9846
- element = $compile (
9847
- '<minion-component>' +
9848
- '<minion>stuart</minion>' +
9849
- '<span>dorothy</span>' +
9850
- '<minion>kevin</minion>' +
9851
- '</minion-component>' ) ( $rootScope ) ;
9852
- $rootScope . $apply ( ) ;
9853
- expect ( element . children ( ) . eq ( 0 ) . text ( ) ) . toEqual ( 'default boss content' ) ;
9854
- expect ( element . children ( ) . eq ( 1 ) . text ( ) ) . toEqual ( 'stuartkevin' ) ;
9855
- expect ( element . children ( ) . eq ( 2 ) . text ( ) ) . toEqual ( 'dorothy' ) ;
9856
- } ) ;
9857
- } ) ;
9858
9866
} ) ;
9859
9867
9860
9868
0 commit comments