@@ -371,28 +371,27 @@ describe('$compile', function() {
371
371
expect ( $document . scope ( ) ) . toBe ( $rootScope ) ;
372
372
} ) ) ;
373
373
374
+ it ( 'should wrap root text nodes in spans' , inject ( function ( $compile , $rootScope ) {
375
+ element = jqLite ( '<div>A<a>B</a>C</div>' ) ;
376
+ var text = element . contents ( ) ;
377
+ expect ( text [ 0 ] . nodeName ) . toEqual ( '#text' ) ;
378
+ text = $compile ( text ) ( $rootScope ) ;
379
+ expect ( text [ 0 ] . nodeName ) . toEqual ( 'SPAN' ) ;
380
+ expect ( element . find ( 'span' ) . text ( ) ) . toEqual ( 'A<a>B</a>C' ) ;
381
+ } ) ) ;
382
+
374
383
375
- it ( 'should not wrap root text nodes in spans' , function ( ) {
384
+ it ( 'should not wrap root whitespace text nodes in spans' , function ( ) {
376
385
element = jqLite (
377
- '<div> <div>A</div>\n ' +
378
- '<div>B</div>C\t\n ' +
386
+ '<div> <div>A</div>\n ' + // The spaces and newlines here should not get wrapped
387
+ '<div>B</div>C\t\n ' + // The "C", tabs and spaces here will be wrapped
379
388
'</div>' ) ;
380
389
$compile ( element . contents ( ) ) ( $rootScope ) ;
381
390
var spans = element . find ( 'span' ) ;
382
- expect ( spans . length ) . toEqual ( 0 ) ;
391
+ expect ( spans . length ) . toEqual ( 1 ) ;
392
+ expect ( spans . text ( ) . indexOf ( 'C' ) ) . toEqual ( 0 ) ;
383
393
} ) ;
384
394
385
-
386
- it ( 'should be able to compile text nodes at the root' , inject ( function ( $rootScope ) {
387
- element = jqLite ( '<div>Name: {{name}}<br />\nColor: {{color}}</div>' ) ;
388
- $rootScope . name = 'Lucas' ;
389
- $rootScope . color = 'blue' ;
390
- $compile ( element . contents ( ) ) ( $rootScope ) ;
391
- $rootScope . $digest ( ) ;
392
- expect ( element . text ( ) ) . toEqual ( 'Name: Lucas\nColor: blue' ) ;
393
- } ) ) ;
394
-
395
-
396
395
it ( 'should not leak memory when there are top level empty text nodes' , function ( ) {
397
396
// We compile the contents of element (i.e. not element itself)
398
397
// Then delete these contents and check the cache has been reset to zero
@@ -6595,8 +6594,8 @@ describe('$compile', function() {
6595
6594
$rootScope . x = 'root' ;
6596
6595
$rootScope . $apply ( ) ;
6597
6596
expect ( element . text ( ) ) . toEqual ( 'W:iso-1-2;T:root-2-3;' ) ;
6598
- expect ( jqLite ( jqLite ( element . find ( 'li' ) [ 1 ] ) . contents ( ) [ 0 ] ) . text ( ) ) . toEqual ( 'T:root-2-3' ) ;
6599
- expect ( jqLite ( element . find ( 'span' ) [ 0 ] ) . text ( ) ) . toEqual ( ';' ) ;
6597
+ expect ( jqLite ( element . find ( 'span' ) [ 0 ] ) . text ( ) ) . toEqual ( 'T:root-2-3' ) ;
6598
+ expect ( jqLite ( element . find ( 'span' ) [ 1 ] ) . text ( ) ) . toEqual ( ';' ) ;
6600
6599
} ) ;
6601
6600
} ) ;
6602
6601
@@ -6634,37 +6633,6 @@ describe('$compile', function() {
6634
6633
} ) ;
6635
6634
6636
6635
6637
- it ( 'should not merge text elements from transcluded content' , function ( ) {
6638
- module ( function ( ) {
6639
- directive ( 'foo' , valueFn ( {
6640
- transclude : 'content' ,
6641
- template : '<div>This is before {{before}}. </div>' ,
6642
- link : function ( scope , element , attr , ctrls , $transclude ) {
6643
- var futureParent = element . children ( ) . eq ( 0 ) ;
6644
- $transclude ( function ( clone ) {
6645
- futureParent . append ( clone ) ;
6646
- } , futureParent ) ;
6647
- } ,
6648
- scope : true
6649
- } ) ) ;
6650
- } ) ;
6651
- inject ( function ( $rootScope , $compile ) {
6652
- element = $compile ( '<div><div foo>This is after {{after}}</div></div>' ) ( $rootScope ) ;
6653
- $rootScope . before = "BEFORE" ;
6654
- $rootScope . after = "AFTER" ;
6655
- $rootScope . $apply ( ) ;
6656
- expect ( element . text ( ) ) . toEqual ( 'This is before BEFORE. This is after AFTER' ) ;
6657
-
6658
- $rootScope . before = "Not-Before" ;
6659
- $rootScope . after = "AfTeR" ;
6660
- $rootScope . $$childHead . before = "BeFoRe" ;
6661
- $rootScope . $$childHead . after = "Not-After" ;
6662
- $rootScope . $apply ( ) ;
6663
- expect ( element . text ( ) ) . toEqual ( 'This is before BeFoRe. This is after AfTeR' ) ;
6664
- } ) ;
6665
- } ) ;
6666
-
6667
-
6668
6636
it ( 'should only allow one content transclusion per element' , function ( ) {
6669
6637
module ( function ( ) {
6670
6638
directive ( 'first' , valueFn ( {
@@ -6963,11 +6931,11 @@ describe('$compile', function() {
6963
6931
transclude : true ,
6964
6932
replace : true ,
6965
6933
scope : true ,
6966
- template : '<div><span>I:{{$$transcluded}}</span><span ng-transclude></span ></div>'
6934
+ template : '<div><span>I:{{$$transcluded}}</span><div ng-transclude></div ></div>'
6967
6935
} ;
6968
6936
} ) ;
6969
6937
} ) ;
6970
- inject ( function ( $rootScope , $compile ) {
6938
+ inject ( function ( log , $rootScope , $compile ) {
6971
6939
element = $compile ( '<div><div trans>T:{{$$transcluded}}</div></div>' ) ( $rootScope ) ;
6972
6940
$rootScope . $apply ( ) ;
6973
6941
expect ( jqLite ( element . find ( 'span' ) [ 0 ] ) . text ( ) ) . toEqual ( 'I:' ) ;
@@ -6986,10 +6954,10 @@ describe('$compile', function() {
6986
6954
} ;
6987
6955
} ) ;
6988
6956
} ) ;
6989
- inject ( function ( $rootScope , $compile ) {
6957
+ inject ( function ( log , $rootScope , $compile ) {
6990
6958
element = $compile ( '<div trans>unicorn!</div>' ) ( $rootScope ) ;
6991
6959
$rootScope . $apply ( ) ;
6992
- expect ( sortedHtml ( element . html ( ) ) ) . toEqual ( '<div ng-transclude="">unicorn!</div>' ) ;
6960
+ expect ( sortedHtml ( element . html ( ) ) ) . toEqual ( '<div ng-transclude=""><span> unicorn!</span> </div>' ) ;
6993
6961
} ) ;
6994
6962
} ) ;
6995
6963
0 commit comments