From d607a556cde4a24d6158161ea66489dab2b7d033 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Tue, 23 Jun 2015 15:50:50 +0300 Subject: [PATCH] test($compile): test default value for optional attribute with new scope Related to #12151 Closes #12194 --- test/ng/compileSpec.js | 78 +++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 253ae6e50028..794a95a48ebf 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -3578,7 +3578,7 @@ describe('$compile', function() { controller: function($scope) { $scope.prop = $scope.prop || 'default'; this.getProp = function() { - return $scope.prop; + return $scope.prop; }; }, controllerAs: 'ctrl', @@ -4458,31 +4458,61 @@ describe('$compile', function() { }); }); - it('should not overwrite @-bound property each digest when not present', function() { - module(function($compileProvider) { - $compileProvider.directive('testDir', valueFn({ - scope: {}, - bindToController: { - prop: '@' - }, - controller: function() { - var self = this; - this.prop = this.prop || 'default'; - this.getProp = function() { - return self.prop; - }; - }, - controllerAs: 'ctrl', - template: '

' - })); + describe('should not overwrite @-bound property each digest when not present', function() { + it('when creating new scope', function() { + module(function($compileProvider) { + $compileProvider.directive('testDir', valueFn({ + scope: true, + bindToController: { + prop: '@' + }, + controller: function() { + var self = this; + this.prop = this.prop || 'default'; + this.getProp = function() { + return self.prop; + }; + }, + controllerAs: 'ctrl', + template: '

' + })); + }); + inject(function($compile, $rootScope) { + element = $compile('
')($rootScope); + var scope = element.scope(); + expect(scope.ctrl.getProp()).toBe('default'); + + $rootScope.$digest(); + expect(scope.ctrl.getProp()).toBe('default'); + }); }); - inject(function($compile, $rootScope) { - element = $compile('
')($rootScope); - var scope = element.isolateScope(); - expect(scope.ctrl.getProp()).toBe('default'); - $rootScope.$digest(); - expect(scope.ctrl.getProp()).toBe('default'); + it('when creating isolate scope', function() { + module(function($compileProvider) { + $compileProvider.directive('testDir', valueFn({ + scope: {}, + bindToController: { + prop: '@' + }, + controller: function() { + var self = this; + this.prop = this.prop || 'default'; + this.getProp = function() { + return self.prop; + }; + }, + controllerAs: 'ctrl', + template: '

' + })); + }); + inject(function($compile, $rootScope) { + element = $compile('
')($rootScope); + var scope = element.isolateScope(); + expect(scope.ctrl.getProp()).toBe('default'); + + $rootScope.$digest(); + expect(scope.ctrl.getProp()).toBe('default'); + }); }); }); });