@@ -2521,10 +2521,17 @@ describe('$compile', function() {
2521
2521
} ;
2522
2522
2523
2523
expect ( func ) . not . toThrow ( ) ;
2524
- expect ( element . find ( 'span' ) . scope ( ) ) . toBe ( element . isolateScope ( ) ) ;
2525
- expect ( element . isolateScope ( ) ) . not . toBe ( $rootScope ) ;
2526
- expect ( element . isolateScope ( ) [ 'constructor' ] ) . toBe ( $rootScope . constructor ) ;
2527
- expect ( element . isolateScope ( ) [ 'valueOf' ] ) . toBeUndefined ( ) ;
2524
+ var scope = element . isolateScope ( ) ;
2525
+ expect ( element . find ( 'span' ) . scope ( ) ) . toBe ( scope ) ;
2526
+ expect ( scope ) . not . toBe ( $rootScope ) ;
2527
+
2528
+ // Not shadowed because optional
2529
+ expect ( scope . constructor ) . toBe ( $rootScope . constructor ) ;
2530
+ expect ( scope . hasOwnProperty ( 'constructor' ) ) . toBe ( false ) ;
2531
+
2532
+ // Shadowed with undefined because not optional
2533
+ expect ( scope . valueOf ) . toBeUndefined ( ) ;
2534
+ expect ( scope . hasOwnProperty ( 'valueOf' ) ) . toBe ( true ) ;
2528
2535
} )
2529
2536
) ;
2530
2537
@@ -2539,10 +2546,13 @@ describe('$compile', function() {
2539
2546
} ;
2540
2547
2541
2548
expect ( func ) . not . toThrow ( ) ;
2542
- expect ( element . find ( 'span' ) . scope ( ) ) . toBe ( element . isolateScope ( ) ) ;
2543
- expect ( element . isolateScope ( ) ) . not . toBe ( $rootScope ) ;
2544
- expect ( element . isolateScope ( ) [ 'constructor' ] ) . toBe ( 'constructor' ) ;
2545
- expect ( element . isolateScope ( ) [ 'valueOf' ] ) . toBe ( 'valueOf' ) ;
2549
+ var scope = element . isolateScope ( ) ;
2550
+ expect ( element . find ( 'span' ) . scope ( ) ) . toBe ( scope ) ;
2551
+ expect ( scope ) . not . toBe ( $rootScope ) ;
2552
+ expect ( scope . constructor ) . toBe ( 'constructor' ) ;
2553
+ expect ( scope . hasOwnProperty ( 'constructor' ) ) . toBe ( true ) ;
2554
+ expect ( scope . valueOf ) . toBe ( 'valueOf' ) ;
2555
+ expect ( scope . hasOwnProperty ( 'valueOf' ) ) . toBe ( true ) ;
2546
2556
} )
2547
2557
) ;
2548
2558
@@ -2553,10 +2563,17 @@ describe('$compile', function() {
2553
2563
} ;
2554
2564
2555
2565
expect ( func ) . not . toThrow ( ) ;
2556
- expect ( element . find ( 'span' ) . scope ( ) ) . toBe ( element . isolateScope ( ) ) ;
2557
- expect ( element . isolateScope ( ) ) . not . toBe ( $rootScope ) ;
2558
- expect ( element . isolateScope ( ) [ 'constructor' ] ) . toBe ( $rootScope . constructor ) ;
2559
- expect ( element . isolateScope ( ) [ 'valueOf' ] ) . toBeUndefined ( ) ;
2566
+ var scope = element . isolateScope ( ) ;
2567
+ expect ( element . find ( 'span' ) . scope ( ) ) . toBe ( scope ) ;
2568
+ expect ( scope ) . not . toBe ( $rootScope ) ;
2569
+
2570
+ // Does not shadow value because optional
2571
+ expect ( scope . constructor ) . toBe ( $rootScope . constructor ) ;
2572
+ expect ( scope . hasOwnProperty ( 'constructor' ) ) . toBe ( false ) ;
2573
+
2574
+ // Shadows value because not optional
2575
+ expect ( scope . valueOf ) . toBeUndefined ( ) ;
2576
+ expect ( scope . hasOwnProperty ( 'valueOf' ) ) . toBe ( true ) ;
2560
2577
} )
2561
2578
) ;
2562
2579
@@ -4415,6 +4432,34 @@ describe('$compile', function() {
4415
4432
childScope . theCtrl . test ( ) ;
4416
4433
} ) ;
4417
4434
} ) ;
4435
+
4436
+ it ( 'should not overwrite @-bound property each digest when not present' , function ( ) {
4437
+ module ( function ( $compileProvider ) {
4438
+ $compileProvider . directive ( 'testDir' , valueFn ( {
4439
+ scope : { } ,
4440
+ bindToController : {
4441
+ prop : '@'
4442
+ } ,
4443
+ controller : function ( ) {
4444
+ var self = this ;
4445
+ this . prop = this . prop || 'default' ;
4446
+ this . getProp = function ( ) {
4447
+ return self . prop ;
4448
+ } ;
4449
+ } ,
4450
+ controllerAs : 'ctrl' ,
4451
+ template : '<p></p>'
4452
+ } ) ) ;
4453
+ } ) ;
4454
+ inject ( function ( $compile , $rootScope ) {
4455
+ element = $compile ( '<div test-dir></div>' ) ( $rootScope ) ;
4456
+ var scope = element . isolateScope ( ) ;
4457
+ expect ( scope . ctrl . getProp ( ) ) . toBe ( 'default' ) ;
4458
+
4459
+ $rootScope . $digest ( ) ;
4460
+ expect ( scope . ctrl . getProp ( ) ) . toBe ( 'default' ) ;
4461
+ } ) ;
4462
+ } ) ;
4418
4463
} ) ;
4419
4464
4420
4465
0 commit comments