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

test($compile): ensure equal but different instance changes are detected in onChanges #15300

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5453,7 +5453,7 @@ describe('$compile', function() {

this.$onChanges = function(changes) {
if (changes.input) {
log.push(['$onChanges', changes.input]);
log.push(['$onChanges', copy(changes.input)]);
}
};
}
Expand Down Expand Up @@ -5482,6 +5482,53 @@ describe('$compile', function() {
});
});

it('should not update isolate again after $onInit if outer object reference has not changed', function() {
module('owComponentTest');
inject(function() {
$rootScope.name = ['outer'];
compile('<ow-component input="name"></ow-component>');

expect($rootScope.name).toEqual(['outer']);
expect(component.input).toEqual('$onInit');

$rootScope.name[0] = 'inner';
$rootScope.$digest();

expect($rootScope.name).toEqual(['inner']);
expect(component.input).toEqual('$onInit');

expect(log).toEqual([
'constructor',
['$onChanges', jasmine.objectContaining({ currentValue: ['outer'] })],
'$onInit'
]);
});
});

it('should update isolate again after $onInit if outer object reference changes even if equal', function() {
module('owComponentTest');
inject(function() {
$rootScope.name = ['outer'];
compile('<ow-component input="name"></ow-component>');

expect($rootScope.name).toEqual(['outer']);
expect(component.input).toEqual('$onInit');

$rootScope.name = ['outer'];
$rootScope.$digest();

expect($rootScope.name).toEqual(['outer']);
expect(component.input).toEqual(['outer']);

expect(log).toEqual([
'constructor',
['$onChanges', jasmine.objectContaining({ currentValue: ['outer'] })],
'$onInit',
['$onChanges', jasmine.objectContaining({ previousValue: ['outer'], currentValue: ['outer'] })]
]);
});
});

it('should not update isolate again after $onInit if outer is a literal', function() {
module('owComponentTest');
inject(function() {
Expand Down