@@ -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
@@ -3554,6 +3571,31 @@ describe('$compile', function() {
3554
3571
}));
3555
3572
3556
3573
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
+
3557
3599
describe('bind-once', function() {
3558
3600
3559
3601
function countWatches(scope) {
@@ -4415,6 +4457,34 @@ describe('$compile', function() {
4415
4457
childScope.theCtrl.test();
4416
4458
});
4417
4459
});
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
+ });
4418
4488
});
4419
4489
4420
4490
0 commit comments