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

Commit 31d55a8

Browse files
jbedardgkalpak
authored andcommitted
test($compile): ensure equal but different instance changes are detected in onChanges
Closes #15300
1 parent fd24ad3 commit 31d55a8

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

test/ng/compileSpec.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5403,7 +5403,7 @@ describe('$compile', function() {
54035403

54045404
this.$onChanges = function(changes) {
54055405
if (changes.input) {
5406-
log.push(['$onChanges', changes.input]);
5406+
log.push(['$onChanges', copy(changes.input)]);
54075407
}
54085408
};
54095409
}
@@ -5432,6 +5432,53 @@ describe('$compile', function() {
54325432
});
54335433
});
54345434

5435+
it('should not update isolate again after $onInit if outer object reference has not changed', function() {
5436+
module('owComponentTest');
5437+
inject(function() {
5438+
$rootScope.name = ['outer'];
5439+
compile('<ow-component input="name"></ow-component>');
5440+
5441+
expect($rootScope.name).toEqual(['outer']);
5442+
expect(component.input).toEqual('$onInit');
5443+
5444+
$rootScope.name[0] = 'inner';
5445+
$rootScope.$digest();
5446+
5447+
expect($rootScope.name).toEqual(['inner']);
5448+
expect(component.input).toEqual('$onInit');
5449+
5450+
expect(log).toEqual([
5451+
'constructor',
5452+
['$onChanges', jasmine.objectContaining({ currentValue: ['outer'] })],
5453+
'$onInit'
5454+
]);
5455+
});
5456+
});
5457+
5458+
it('should update isolate again after $onInit if outer object reference changes even if equal', function() {
5459+
module('owComponentTest');
5460+
inject(function() {
5461+
$rootScope.name = ['outer'];
5462+
compile('<ow-component input="name"></ow-component>');
5463+
5464+
expect($rootScope.name).toEqual(['outer']);
5465+
expect(component.input).toEqual('$onInit');
5466+
5467+
$rootScope.name = ['outer'];
5468+
$rootScope.$digest();
5469+
5470+
expect($rootScope.name).toEqual(['outer']);
5471+
expect(component.input).toEqual(['outer']);
5472+
5473+
expect(log).toEqual([
5474+
'constructor',
5475+
['$onChanges', jasmine.objectContaining({ currentValue: ['outer'] })],
5476+
'$onInit',
5477+
['$onChanges', jasmine.objectContaining({ previousValue: ['outer'], currentValue: ['outer'] })]
5478+
]);
5479+
});
5480+
});
5481+
54355482
it('should not update isolate again after $onInit if outer is a literal', function() {
54365483
module('owComponentTest');
54375484
inject(function() {

0 commit comments

Comments
 (0)