@@ -2823,10 +2823,67 @@ describe('$compile', function() {
2823
2823
expect ( jqLite ( element . find ( 'span' ) [ 1 ] ) . text ( ) ) . toEqual ( 'T:true' ) ;
2824
2824
} ) ;
2825
2825
} ) ;
2826
+
2827
+
2828
+ it ( 'should make the result of a transclusion available to the parent directive in post-linking phase (template)' ,
2829
+ function ( ) {
2830
+ module ( function ( ) {
2831
+ directive ( 'trans' , function ( log ) {
2832
+ return {
2833
+ transclude : true ,
2834
+ template : '<div ng-transclude></div>' ,
2835
+ link : {
2836
+ pre : function ( $scope , $element ) {
2837
+ log ( 'pre(' + $element . text ( ) + ')' ) ;
2838
+ } ,
2839
+ post : function ( $scope , $element ) {
2840
+ log ( 'post(' + $element . text ( ) + ')' ) ;
2841
+ }
2842
+ }
2843
+ } ;
2844
+ } ) ;
2845
+ } ) ;
2846
+ inject ( function ( log , $rootScope , $compile ) {
2847
+ element = $compile ( '<div trans><span>unicorn!</span></div>' ) ( $rootScope ) ;
2848
+ $rootScope . $apply ( ) ;
2849
+ expect ( log ) . toEqual ( 'pre(); post(unicorn!)' ) ;
2850
+ } ) ;
2851
+ } ) ;
2852
+
2853
+
2854
+ it ( 'should make the result of a transclusion available to the parent directive in pre- and post- linking phase (templateUrl)' ,
2855
+ function ( ) {
2856
+ // when compiling an async directive the transclusion is always processed before the directive
2857
+ // this is different compared to sync directive. delaying the transclusion makes little sense.
2858
+
2859
+ module ( function ( ) {
2860
+ directive ( 'trans' , function ( log ) {
2861
+ return {
2862
+ transclude : true ,
2863
+ templateUrl : 'trans.html' ,
2864
+ link : {
2865
+ pre : function ( $scope , $element ) {
2866
+ log ( 'pre(' + $element . text ( ) + ')' ) ;
2867
+ } ,
2868
+ post : function ( $scope , $element ) {
2869
+ log ( 'post(' + $element . text ( ) + ')' ) ;
2870
+ }
2871
+ }
2872
+ } ;
2873
+ } ) ;
2874
+ } ) ;
2875
+ inject ( function ( log , $rootScope , $compile , $templateCache ) {
2876
+ $templateCache . put ( 'trans.html' , '<div ng-transclude></div>' ) ;
2877
+
2878
+ element = $compile ( '<div trans><span>unicorn!</span></div>' ) ( $rootScope ) ;
2879
+ $rootScope . $apply ( ) ;
2880
+ expect ( log ) . toEqual ( 'pre(unicorn!); post(unicorn!)' ) ;
2881
+ } ) ;
2882
+ } ) ;
2826
2883
} ) ;
2827
2884
2828
2885
2829
- describe ( 'img[src] sanitization' , function ( $sce ) {
2886
+ describe ( 'img[src] sanitization' , function ( ) {
2830
2887
it ( 'should NOT require trusted values for img src' , inject ( function ( $rootScope , $compile , $sce ) {
2831
2888
element = $compile ( '<img src="{{testUrl}}"></img>' ) ( $rootScope ) ;
2832
2889
$rootScope . testUrl = 'http://example.com/image.png' ;
0 commit comments