Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 28c1669

Browse files
gkalpaklgalfaso
authored andcommitted
test($compile): test default value for optional attribute with new scope
Related to #12151 Closes #12194
1 parent 14638f4 commit 28c1669

File tree

1 file changed

+54
-24
lines changed

1 file changed

+54
-24
lines changed

test/ng/compileSpec.js

+54-24
Original file line numberDiff line numberDiff line change
@@ -3578,7 +3578,7 @@ describe('$compile', function() {
35783578
controller: function($scope) {
35793579
$scope.prop = $scope.prop || 'default';
35803580
this.getProp = function() {
3581-
return $scope.prop;
3581+
return $scope.prop;
35823582
};
35833583
},
35843584
controllerAs: 'ctrl',
@@ -4458,31 +4458,61 @@ describe('$compile', function() {
44584458
});
44594459
});
44604460

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-
}));
4461+
describe('should not overwrite @-bound property each digest when not present', function() {
4462+
it('when creating new scope', function() {
4463+
module(function($compileProvider) {
4464+
$compileProvider.directive('testDir', valueFn({
4465+
scope: true,
4466+
bindToController: {
4467+
prop: '@'
4468+
},
4469+
controller: function() {
4470+
var self = this;
4471+
this.prop = this.prop || 'default';
4472+
this.getProp = function() {
4473+
return self.prop;
4474+
};
4475+
},
4476+
controllerAs: 'ctrl',
4477+
template: '<p></p>'
4478+
}));
4479+
});
4480+
inject(function($compile, $rootScope) {
4481+
element = $compile('<div test-dir></div>')($rootScope);
4482+
var scope = element.scope();
4483+
expect(scope.ctrl.getProp()).toBe('default');
4484+
4485+
$rootScope.$digest();
4486+
expect(scope.ctrl.getProp()).toBe('default');
4487+
});
44784488
});
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');
44834489

4484-
$rootScope.$digest();
4485-
expect(scope.ctrl.getProp()).toBe('default');
4490+
it('when creating isolate scope', function() {
4491+
module(function($compileProvider) {
4492+
$compileProvider.directive('testDir', valueFn({
4493+
scope: {},
4494+
bindToController: {
4495+
prop: '@'
4496+
},
4497+
controller: function() {
4498+
var self = this;
4499+
this.prop = this.prop || 'default';
4500+
this.getProp = function() {
4501+
return self.prop;
4502+
};
4503+
},
4504+
controllerAs: 'ctrl',
4505+
template: '<p></p>'
4506+
}));
4507+
});
4508+
inject(function($compile, $rootScope) {
4509+
element = $compile('<div test-dir></div>')($rootScope);
4510+
var scope = element.isolateScope();
4511+
expect(scope.ctrl.getProp()).toBe('default');
4512+
4513+
$rootScope.$digest();
4514+
expect(scope.ctrl.getProp()).toBe('default');
4515+
});
44864516
});
44874517
});
44884518
});

0 commit comments

Comments
 (0)