From bb3c1f248f835cbc43db69a6da643dc208fb96ca Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Thu, 20 Oct 2016 01:00:32 -0700 Subject: [PATCH] test($compile): ensure equal but different instance changes are detected in onChanges --- test/ng/compileSpec.js | 49 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 544baf8a74ca..4c4f1f589a2f 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -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)]); } }; } @@ -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(''); + + 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(''); + + 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() {