@@ -2080,17 +2080,49 @@ describe('$compile', function() {
2080
2080
) ) ;
2081
2081
2082
2082
2083
- it ( 'should work when directive is in a repeater' , inject (
2084
- function ( $compile , $httpBackend , $rootScope ) {
2085
- $httpBackend . expect ( 'GET' , 'hello.html' ) .
2083
+ describe ( 'when directive is in a repeater' , function ( ) {
2084
+ var is ;
2085
+ beforeEach ( function ( ) {
2086
+ is = [ 1 , 2 ] ;
2087
+ } ) ;
2088
+
2089
+ function runTest ( ) {
2090
+ inject ( function ( $compile , $httpBackend , $rootScope ) {
2091
+ $httpBackend . expect ( 'GET' , 'hello.html' ) .
2086
2092
respond ( '<span>i=<span ng-transclude></span>;</span>' ) ;
2087
- element = jqLite ( '<div><b class=hello ng-repeat="i in [1,2 ]">{{i}}</b></div>' ) ;
2088
- $compile ( element ) ( $rootScope ) ;
2093
+ element = jqLite ( '<div><b class=hello ng-repeat="i in [' + is + ' ]">{{i}}</b></div>') ;
2094
+ $compile ( element ) ( $rootScope ) ;
2089
2095
2090
- $httpBackend . flush ( ) ;
2091
- expect ( element . text ( ) ) . toEqual ( 'i=1;i=2;' ) ;
2096
+ $httpBackend . flush ( ) ;
2097
+ expect ( element . text ( ) ) . toEqual ( 'i=' + is . join ( ';i=' ) + ';' ) ;
2098
+ } ) ;
2092
2099
}
2093
- ) ) ;
2100
+
2101
+ it ( 'should work in jqLite and jQuery with jQuery.cleanData last patched by Angular' , runTest ) ;
2102
+
2103
+ if ( jQuery ) {
2104
+ it ( 'should work with another library patching jQuery.cleanData after Angular' , function ( ) {
2105
+ var cleanedCount = 0 ;
2106
+ var currentCleanData = jqLite . cleanData ;
2107
+ jqLite . cleanData = function ( elems ) {
2108
+ cleanedCount += elems . length ;
2109
+ // Don't return the output and explicitly pass only the first parameter
2110
+ // so that we're sure we're not relying on either of them. jQuery UI patch
2111
+ // behaves in this way.
2112
+ currentCleanData ( elems ) ;
2113
+ } ;
2114
+
2115
+ runTest ( ) ;
2116
+
2117
+ // The initial ng-repeat div is dumped after parsing hence we expect cleanData
2118
+ // count to be one larger than size of the iterated array.
2119
+ expect ( cleanedCount ) . toBe ( is . length + 1 ) ;
2120
+
2121
+ // Restore the previous cleanData.
2122
+ jqLite . cleanData = currentCleanData ;
2123
+ } ) ;
2124
+ }
2125
+ } ) ;
2094
2126
2095
2127
describe ( 'replace and not exactly one root element' , function ( ) {
2096
2128
@@ -8573,46 +8605,46 @@ describe('$compile', function() {
8573
8605
} ) ;
8574
8606
} ) ;
8575
8607
8576
- if ( jQuery ) {
8577
- describe ( 'cleaning up after a replaced element' , function ( ) {
8578
- var $compile , xs ;
8579
- beforeEach ( inject ( function ( _$compile_ ) {
8580
- $compile = _$compile_ ;
8581
- xs = [ 0 , 1 ] ;
8582
- } ) ) ;
8608
+ describe ( 'cleaning up after a replaced element' , function ( ) {
8609
+ var $compile , xs ;
8610
+ beforeEach ( inject ( function ( _$compile_ ) {
8611
+ $compile = _$compile_ ;
8612
+ xs = [ 0 , 1 ] ;
8613
+ } ) ) ;
8583
8614
8584
- function testCleanup ( ) {
8585
- var privateData , firstRepeatedElem ;
8615
+ function testCleanup ( ) {
8616
+ var privateData , firstRepeatedElem ;
8586
8617
8587
- element = $compile ( '<div><div ng-repeat="x in xs" ng-click="noop()">{{x}}</div></div>' ) ( $rootScope ) ;
8618
+ element = $compile ( '<div><div ng-repeat="x in xs" ng-click="noop()">{{x}}</div></div>' ) ( $rootScope ) ;
8588
8619
8589
- $rootScope . $apply ( 'xs = [' + xs + ']' ) ;
8590
- firstRepeatedElem = element . children ( '.ng-scope' ) . eq ( 0 ) ;
8620
+ $rootScope . $apply ( 'xs = [' + xs + ']' ) ;
8621
+ firstRepeatedElem = element . children ( '.ng-scope' ) . eq ( 0 ) ;
8591
8622
8592
- expect ( firstRepeatedElem . data ( '$scope' ) ) . toBeDefined ( ) ;
8593
- privateData = jQuery . _data ( firstRepeatedElem [ 0 ] ) ;
8594
- expect ( privateData . events ) . toBeDefined ( ) ;
8595
- expect ( privateData . events . click ) . toBeDefined ( ) ;
8596
- expect ( privateData . events . click [ 0 ] ) . toBeDefined ( ) ;
8623
+ expect ( firstRepeatedElem . data ( '$scope' ) ) . toBeDefined ( ) ;
8624
+ privateData = jqLite . _data ( firstRepeatedElem [ 0 ] ) ;
8625
+ expect ( privateData . events ) . toBeDefined ( ) ;
8626
+ expect ( privateData . events . click ) . toBeDefined ( ) ;
8627
+ expect ( privateData . events . click [ 0 ] ) . toBeDefined ( ) ;
8597
8628
8598
- // Ensure the AngularJS $destroy event is still sent
8599
- var destroyCount = 0 ;
8600
- element . find ( 'div' ) . on ( '$destroy' , function ( ) { destroyCount ++ ; } ) ;
8629
+ // Ensure the AngularJS $destroy event is still sent
8630
+ var destroyCount = 0 ;
8631
+ element . find ( 'div' ) . on ( '$destroy' , function ( ) { destroyCount ++ ; } ) ;
8601
8632
8602
- $rootScope . $apply ( 'xs = null' ) ;
8633
+ $rootScope . $apply ( 'xs = null' ) ;
8603
8634
8604
- expect ( destroyCount ) . toBe ( 2 ) ;
8605
- expect ( firstRepeatedElem . data ( '$scope' ) ) . not . toBeDefined ( ) ;
8606
- privateData = jQuery . _data ( firstRepeatedElem [ 0 ] ) ;
8607
- expect ( privateData && privateData . events ) . not . toBeDefined ( ) ;
8608
- }
8635
+ expect ( destroyCount ) . toBe ( 2 ) ;
8636
+ expect ( firstRepeatedElem . data ( '$scope' ) ) . not . toBeDefined ( ) ;
8637
+ privateData = jqLite . _data ( firstRepeatedElem [ 0 ] ) ;
8638
+ expect ( privateData && privateData . events ) . not . toBeDefined ( ) ;
8639
+ }
8609
8640
8610
- it ( 'should work without external libraries (except jQuery)' , testCleanup ) ;
8641
+ it ( 'should work without external libraries (except jQuery)' , testCleanup ) ;
8611
8642
8643
+ if ( jQuery ) {
8612
8644
it ( 'should work with another library patching jQuery.cleanData after AngularJS' , function ( ) {
8613
8645
var cleanedCount = 0 ;
8614
- var currentCleanData = jQuery . cleanData ;
8615
- jQuery . cleanData = function ( elems ) {
8646
+ var currentCleanData = jqLite . cleanData ;
8647
+ jqLite . cleanData = function ( elems ) {
8616
8648
cleanedCount += elems . length ;
8617
8649
// Don't return the output and explicitly pass only the first parameter
8618
8650
// so that we're sure we're not relying on either of them. jQuery UI patch
@@ -8626,11 +8658,11 @@ describe('$compile', function() {
8626
8658
// and each clone of the ng-repeat template is also removed (xs.length)
8627
8659
expect ( cleanedCount ) . toBe ( xs . length + 1 ) ;
8628
8660
8629
- // Restore the previous jQuery. cleanData.
8630
- jQuery . cleanData = currentCleanData ;
8661
+ // Restore the previous cleanData.
8662
+ jqLite . cleanData = currentCleanData ;
8631
8663
} ) ;
8632
- } ) ;
8633
- }
8664
+ }
8665
+ } ) ;
8634
8666
8635
8667
8636
8668
it ( 'should add a $$transcluded property onto the transcluded scope' , function ( ) {
0 commit comments