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

Commit 41034bb

Browse files
jbedardgkalpak
authored andcommitted
test($compile): ensure equal but different instance changes are detected in onChanges
Closes #15300
1 parent 828f8a6 commit 41034bb

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
@@ -5453,7 +5453,7 @@ describe('$compile', function() {
54535453

54545454
this.$onChanges = function(changes) {
54555455
if (changes.input) {
5456-
log.push(['$onChanges', changes.input]);
5456+
log.push(['$onChanges', copy(changes.input)]);
54575457
}
54585458
};
54595459
}
@@ -5482,6 +5482,53 @@ describe('$compile', function() {
54825482
});
54835483
});
54845484

5485+
it('should not update isolate again after $onInit if outer object reference has not changed', function() {
5486+
module('owComponentTest');
5487+
inject(function() {
5488+
$rootScope.name = ['outer'];
5489+
compile('<ow-component input="name"></ow-component>');
5490+
5491+
expect($rootScope.name).toEqual(['outer']);
5492+
expect(component.input).toEqual('$onInit');
5493+
5494+
$rootScope.name[0] = 'inner';
5495+
$rootScope.$digest();
5496+
5497+
expect($rootScope.name).toEqual(['inner']);
5498+
expect(component.input).toEqual('$onInit');
5499+
5500+
expect(log).toEqual([
5501+
'constructor',
5502+
['$onChanges', jasmine.objectContaining({ currentValue: ['outer'] })],
5503+
'$onInit'
5504+
]);
5505+
});
5506+
});
5507+
5508+
it('should update isolate again after $onInit if outer object reference changes even if equal', function() {
5509+
module('owComponentTest');
5510+
inject(function() {
5511+
$rootScope.name = ['outer'];
5512+
compile('<ow-component input="name"></ow-component>');
5513+
5514+
expect($rootScope.name).toEqual(['outer']);
5515+
expect(component.input).toEqual('$onInit');
5516+
5517+
$rootScope.name = ['outer'];
5518+
$rootScope.$digest();
5519+
5520+
expect($rootScope.name).toEqual(['outer']);
5521+
expect(component.input).toEqual(['outer']);
5522+
5523+
expect(log).toEqual([
5524+
'constructor',
5525+
['$onChanges', jasmine.objectContaining({ currentValue: ['outer'] })],
5526+
'$onInit',
5527+
['$onChanges', jasmine.objectContaining({ previousValue: ['outer'], currentValue: ['outer'] })]
5528+
]);
5529+
});
5530+
});
5531+
54855532
it('should not update isolate again after $onInit if outer is a literal', function() {
54865533
module('owComponentTest');
54875534
inject(function() {

0 commit comments

Comments
 (0)