@@ -5416,21 +5416,21 @@ describe('$compile', function() {
5416
5416
5417
5417
inject ( function ( $rootScope ) {
5418
5418
compile ( '<div other-tpl-dir param1="::foo" param2="bar"></div>' ) ;
5419
- expect ( countWatches ( $rootScope ) ) . toEqual ( 6 ) ; // 4 -> template watch group, 2 -> '='
5419
+ expect ( countWatches ( $rootScope ) ) . toEqual ( 8 ) ; // 4 -> template watch group, 4 -> '='
5420
5420
$rootScope . $digest ( ) ;
5421
5421
expect ( element . html ( ) ) . toBe ( '1:;2:;3:;4:' ) ;
5422
- expect ( countWatches ( $rootScope ) ) . toEqual ( 6 ) ;
5422
+ expect ( countWatches ( $rootScope ) ) . toEqual ( 8 ) ;
5423
5423
5424
5424
$rootScope . foo = 'foo' ;
5425
5425
$rootScope . $digest ( ) ;
5426
5426
expect ( element . html ( ) ) . toBe ( '1:foo;2:;3:foo;4:' ) ;
5427
- expect ( countWatches ( $rootScope ) ) . toEqual ( 4 ) ;
5427
+ expect ( countWatches ( $rootScope ) ) . toEqual ( 6 ) ;
5428
5428
5429
5429
$rootScope . foo = 'baz' ;
5430
5430
$rootScope . bar = 'bar' ;
5431
5431
$rootScope . $digest ( ) ;
5432
5432
expect ( element . html ( ) ) . toBe ( '1:foo;2:bar;3:foo;4:bar' ) ;
5433
- expect ( countWatches ( $rootScope ) ) . toEqual ( 3 ) ;
5433
+ expect ( countWatches ( $rootScope ) ) . toEqual ( 5 ) ;
5434
5434
5435
5435
$rootScope . bar = 'baz' ;
5436
5436
$rootScope . $digest ( ) ;
@@ -5487,18 +5487,18 @@ describe('$compile', function() {
5487
5487
compile ( '<div other-tpl-dir param1="::foo" param2="bar"></div>' ) ;
5488
5488
$rootScope . $digest ( ) ;
5489
5489
expect ( element . html ( ) ) . toBe ( '1:;2:;3:;4:' ) ;
5490
- expect ( countWatches ( $rootScope ) ) . toEqual ( 6 ) ; // 4 -> template watch group, 2 -> '='
5490
+ expect ( countWatches ( $rootScope ) ) . toEqual ( 8 ) ; // 4 -> template watch group, 4 -> '='
5491
5491
5492
5492
$rootScope . foo = 'foo' ;
5493
5493
$rootScope . $digest ( ) ;
5494
5494
expect ( element . html ( ) ) . toBe ( '1:foo;2:;3:foo;4:' ) ;
5495
- expect ( countWatches ( $rootScope ) ) . toEqual ( 4 ) ;
5495
+ expect ( countWatches ( $rootScope ) ) . toEqual ( 6 ) ;
5496
5496
5497
5497
$rootScope . foo = 'baz' ;
5498
5498
$rootScope . bar = 'bar' ;
5499
5499
$rootScope . $digest ( ) ;
5500
5500
expect ( element . html ( ) ) . toBe ( '1:foo;2:bar;3:foo;4:bar' ) ;
5501
- expect ( countWatches ( $rootScope ) ) . toEqual ( 3 ) ;
5501
+ expect ( countWatches ( $rootScope ) ) . toEqual ( 5 ) ;
5502
5502
5503
5503
$rootScope . bar = 'baz' ;
5504
5504
$rootScope . $digest ( ) ;
@@ -5733,6 +5733,37 @@ describe('$compile', function() {
5733
5733
expect ( componentScope . reference ) . toEqual ( { name : 'b' } ) ;
5734
5734
} ) ) ;
5735
5735
5736
+ it ( 'should copy parent changes, even if deep equal to old' , inject ( function ( ) {
5737
+ compile ( '<div><span my-component reference="{person: person}">' ) ;
5738
+
5739
+ $rootScope . person = { name : 'a' } ;
5740
+ $rootScope . $apply ( ) ;
5741
+ expect ( componentScope . reference ) . toEqual ( { person : { name : 'a' } } ) ;
5742
+
5743
+ var instance = componentScope . reference ;
5744
+ $rootScope . person = { name : 'a' } ;
5745
+ $rootScope . $apply ( ) ;
5746
+ expect ( componentScope . reference ) . not . toBe ( instance ) ;
5747
+ expect ( componentScope . reference ) . toEqual ( instance ) ;
5748
+ } ) ) ;
5749
+
5750
+ it ( 'should not copy on parent changes to nested objects' , inject ( function ( ) {
5751
+ compile ( '<div><span my-component reference="{subObj: subObj}">' ) ;
5752
+
5753
+ var subObj = { foo : 42 } ;
5754
+
5755
+ $rootScope . subObj = subObj ;
5756
+ $rootScope . $apply ( ) ;
5757
+ expect ( componentScope . reference ) . toEqual ( { subObj : subObj } ) ;
5758
+
5759
+ var firstVal = componentScope . reference ;
5760
+
5761
+ $rootScope . subObj . foo = true ;
5762
+ $rootScope . $apply ( ) ;
5763
+ expect ( componentScope . reference ) . toBe ( firstVal ) ;
5764
+ expect ( componentScope . reference ) . toEqual ( { subObj : subObj } ) ;
5765
+ } ) ) ;
5766
+
5736
5767
it ( 'should not change the component when parent does not change' , inject ( function ( ) {
5737
5768
compile ( '<div><span my-component reference="{name: name}">' ) ;
5738
5769
@@ -5771,6 +5802,46 @@ describe('$compile', function() {
5771
5802
}
5772
5803
} ) ) ;
5773
5804
5805
+ it ( 'should work with filtered literal objects within array literals' , inject ( function ( ) {
5806
+ $rootScope . gabName = 'Gabriel' ;
5807
+ $rootScope . tonyName = 'Tony' ;
5808
+ $rootScope . query = '' ;
5809
+ $rootScope . $apply ( ) ;
5810
+
5811
+ compile ( '<div><span my-component reference="[{name: gabName}, {name: tonyName}] | filter:query">' ) ;
5812
+
5813
+ expect ( componentScope . reference ) . toEqual ( [ { name : $rootScope . gabName } , { name : $rootScope . tonyName } ] ) ;
5814
+
5815
+ $rootScope . query = 'Gab' ;
5816
+ $rootScope . $apply ( ) ;
5817
+
5818
+ expect ( componentScope . reference ) . toEqual ( [ { name : $rootScope . gabName } ] ) ;
5819
+
5820
+ $rootScope . tonyName = 'Gab' ;
5821
+ $rootScope . $apply ( ) ;
5822
+
5823
+ expect ( componentScope . reference ) . toEqual ( [ { name : $rootScope . gabName } , { name : $rootScope . tonyName } ] ) ;
5824
+ } ) ) ;
5825
+
5826
+ it ( 'should work with filtered constant literal objects within array literals (constant)' , inject ( function ( ) {
5827
+ $rootScope . query = '' ;
5828
+ $rootScope . $apply ( ) ;
5829
+
5830
+ compile ( '<div><span my-component reference="[{name: \'Gabriel\'}, {name: \'Toni\'}] | filter:query">' ) ;
5831
+
5832
+ expect ( componentScope . reference ) . toEqual ( [ { name : 'Gabriel' } , { name : 'Toni' } ] ) ;
5833
+
5834
+ $rootScope . query = 'Gab' ;
5835
+ $rootScope . $apply ( ) ;
5836
+
5837
+ expect ( componentScope . reference ) . toEqual ( [ { name : 'Gabriel' } ] ) ;
5838
+
5839
+ $rootScope . query = 'i' ;
5840
+ $rootScope . $apply ( ) ;
5841
+
5842
+ expect ( componentScope . reference ) . toEqual ( [ { name : 'Gabriel' } , { name : 'Toni' } ] ) ;
5843
+ } ) ) ;
5844
+
5774
5845
} ) ;
5775
5846
5776
5847
} ) ;
@@ -5829,8 +5900,48 @@ describe('$compile', function() {
5829
5900
$rootScope . $apply ( ) ;
5830
5901
5831
5902
expect ( componentScope . colref ) . toEqual ( [ $rootScope . collection [ 0 ] ] ) ;
5832
- expect ( componentScope . colrefAlias ) . toEqual ( [ $rootScope . collection [ 0 ] ] ) ;
5833
- expect ( componentScope . $colrefAlias ) . toEqual ( [ $rootScope . collection [ 0 ] ] ) ;
5903
+ expect ( componentScope . colrefAlias ) . toEqual ( componentScope . colref ) ;
5904
+ expect ( componentScope . $colrefAlias ) . toEqual ( componentScope . colref ) ;
5905
+
5906
+ $rootScope . collection [ 1 ] . name = 'Gab' ;
5907
+ $rootScope . $apply ( ) ;
5908
+
5909
+ expect ( componentScope . colref ) . toEqual ( $rootScope . collection ) ;
5910
+ expect ( componentScope . colrefAlias ) . toEqual ( componentScope . colref ) ;
5911
+ expect ( componentScope . $colrefAlias ) . toEqual ( componentScope . colref ) ;
5912
+ } ) ) ;
5913
+
5914
+ it ( 'should work with filtered objects within a literal collection' , inject ( function ( ) {
5915
+ $rootScope . gab = {
5916
+ name : 'Gabriel' ,
5917
+ value : 18
5918
+ } ;
5919
+ $rootScope . tony = {
5920
+ name : 'Tony' ,
5921
+ value : 91
5922
+ } ;
5923
+ $rootScope . query = '' ;
5924
+ $rootScope . $apply ( ) ;
5925
+
5926
+ compile ( '<div><span my-component colref="[gab, tony] | filter:query" $colref$="[gab, tony] | filter:query">' ) ;
5927
+
5928
+ expect ( componentScope . colref ) . toEqual ( [ $rootScope . gab , $rootScope . tony ] ) ;
5929
+ expect ( componentScope . colrefAlias ) . toEqual ( componentScope . colref ) ;
5930
+ expect ( componentScope . $colrefAlias ) . toEqual ( componentScope . colref ) ;
5931
+
5932
+ $rootScope . query = 'Gab' ;
5933
+ $rootScope . $apply ( ) ;
5934
+
5935
+ expect ( componentScope . colref ) . toEqual ( [ $rootScope . gab ] ) ;
5936
+ expect ( componentScope . colrefAlias ) . toEqual ( componentScope . colref ) ;
5937
+ expect ( componentScope . $colrefAlias ) . toEqual ( componentScope . colref ) ;
5938
+
5939
+ $rootScope . tony . name = 'Gab' ;
5940
+ $rootScope . $apply ( ) ;
5941
+
5942
+ expect ( componentScope . colref ) . toEqual ( [ $rootScope . gab , $rootScope . tony ] ) ;
5943
+ expect ( componentScope . colrefAlias ) . toEqual ( componentScope . colref ) ;
5944
+ expect ( componentScope . $colrefAlias ) . toEqual ( componentScope . colref ) ;
5834
5945
} ) ) ;
5835
5946
5836
5947
it ( 'should update origin scope when isolate scope changes' , inject ( function ( ) {
@@ -6187,6 +6298,47 @@ describe('$compile', function() {
6187
6298
} ) ) ;
6188
6299
6189
6300
6301
+ it ( 'should work with filtered literal objects within array literals' , inject ( function ( ) {
6302
+ $rootScope . gabName = 'Gabriel' ;
6303
+ $rootScope . tonyName = 'Tony' ;
6304
+ $rootScope . query = '' ;
6305
+ $rootScope . $apply ( ) ;
6306
+
6307
+ compile ( '<div><span my-component ow-ref="[{name: gabName}, {name: tonyName}] | filter:query">' ) ;
6308
+
6309
+ expect ( componentScope . owRef ) . toEqual ( [ { name : $rootScope . gabName } , { name : $rootScope . tonyName } ] ) ;
6310
+
6311
+ $rootScope . query = 'Gab' ;
6312
+ $rootScope . $apply ( ) ;
6313
+
6314
+ expect ( componentScope . owRef ) . toEqual ( [ { name : $rootScope . gabName } ] ) ;
6315
+
6316
+ $rootScope . tonyName = 'Gab' ;
6317
+ $rootScope . $apply ( ) ;
6318
+
6319
+ expect ( componentScope . owRef ) . toEqual ( [ { name : $rootScope . gabName } , { name : $rootScope . tonyName } ] ) ;
6320
+ } ) ) ;
6321
+
6322
+ it ( 'should work with filtered constant literal objects within array literals' , inject ( function ( ) {
6323
+ $rootScope . query = '' ;
6324
+ $rootScope . $apply ( ) ;
6325
+
6326
+ compile ( '<div><span my-component ow-ref="[{name: \'Gabriel\'}, {name: \'Toni\'}] | filter:query">' ) ;
6327
+
6328
+ expect ( componentScope . owRef ) . toEqual ( [ { name : 'Gabriel' } , { name : 'Toni' } ] ) ;
6329
+
6330
+ $rootScope . query = 'Gab' ;
6331
+ $rootScope . $apply ( ) ;
6332
+
6333
+ expect ( componentScope . owRef ) . toEqual ( [ { name : 'Gabriel' } ] ) ;
6334
+
6335
+ $rootScope . query = 'i' ;
6336
+ $rootScope . $apply ( ) ;
6337
+
6338
+ expect ( componentScope . owRef ) . toEqual ( [ { name : 'Gabriel' } , { name : 'Toni' } ] ) ;
6339
+ } ) ) ;
6340
+
6341
+
6190
6342
describe ( 'literal objects' , function ( ) {
6191
6343
it ( 'should copy parent changes' , inject ( function ( ) {
6192
6344
compile ( '<div><span my-component ow-ref="{name: name}">' ) ;
0 commit comments