@@ -2521,10 +2521,17 @@ describe('$compile', function() {
25212521 } ;
25222522
25232523 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 ) ;
25282535 } )
25292536 ) ;
25302537
@@ -2539,10 +2546,13 @@ describe('$compile', function() {
25392546 } ;
25402547
25412548 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 ) ;
25462556 } )
25472557 ) ;
25482558
@@ -2553,10 +2563,17 @@ describe('$compile', function() {
25532563 } ;
25542564
25552565 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 ) ;
25602577 } )
25612578 ) ;
25622579
@@ -3554,6 +3571,31 @@ describe('$compile', function() {
35543571 } ) ) ;
35553572
35563573
3574+ it ( 'should not overwrite @-bound property each digest when not present' , function ( ) {
3575+ module ( function ( $compileProvider ) {
3576+ $compileProvider . directive ( 'testDir' , valueFn ( {
3577+ scope : { prop : '@' } ,
3578+ controller : function ( $scope ) {
3579+ $scope . prop = $scope . prop || 'default' ;
3580+ this . getProp = function ( ) {
3581+ return $scope . prop ;
3582+ } ;
3583+ } ,
3584+ controllerAs : 'ctrl' ,
3585+ template : '<p></p>'
3586+ } ) ) ;
3587+ } ) ;
3588+ inject ( function ( $compile , $rootScope ) {
3589+ element = $compile ( '<div test-dir></div>' ) ( $rootScope ) ;
3590+ var scope = element . isolateScope ( ) ;
3591+ expect ( scope . ctrl . getProp ( ) ) . toBe ( 'default' ) ;
3592+
3593+ $rootScope . $digest ( ) ;
3594+ expect ( scope . ctrl . getProp ( ) ) . toBe ( 'default' ) ;
3595+ } ) ;
3596+ } ) ;
3597+
3598+
35573599 describe ( 'bind-once' , function ( ) {
35583600
35593601 function countWatches ( scope ) {
@@ -4415,6 +4457,34 @@ describe('$compile', function() {
44154457 childScope . theCtrl . test ( ) ;
44164458 } ) ;
44174459 } ) ;
4460+
4461+ it ( 'should not overwrite @-bound property each digest when not present' , function ( ) {
4462+ module ( function ( $compileProvider ) {
4463+ $compileProvider . directive ( 'testDir' , valueFn ( {
4464+ scope : { } ,
4465+ bindToController : {
4466+ prop : '@'
4467+ } ,
4468+ controller : function ( ) {
4469+ var self = this ;
4470+ this . prop = this . prop || 'default' ;
4471+ this . getProp = function ( ) {
4472+ return self . prop ;
4473+ } ;
4474+ } ,
4475+ controllerAs : 'ctrl' ,
4476+ template : '<p></p>'
4477+ } ) ) ;
4478+ } ) ;
4479+ inject ( function ( $compile , $rootScope ) {
4480+ element = $compile ( '<div test-dir></div>' ) ( $rootScope ) ;
4481+ var scope = element . isolateScope ( ) ;
4482+ expect ( scope . ctrl . getProp ( ) ) . toBe ( 'default' ) ;
4483+
4484+ $rootScope . $digest ( ) ;
4485+ expect ( scope . ctrl . getProp ( ) ) . toBe ( 'default' ) ;
4486+ } ) ;
4487+ } ) ;
44184488 } ) ;
44194489
44204490
0 commit comments