From 6452707d4098235bdbde34e790aee05a1b091218 Mon Sep 17 00:00:00 2001 From: Gonzalo Ruiz de Villa Date: Thu, 2 May 2013 13:05:22 +0200 Subject: fix($rootScope) ensure $watchCollection correctly handles arrayLike objects --- test/ng/rootScopeSpec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test') diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index cd8d4109..cac7c160 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -463,6 +463,23 @@ describe('Scope', function() { $rootScope.$digest(); expect(log).toEqual([ '[{},[]]' ]); }); + + it('should watch array-like objects like arrays', function () { + var arrayLikelog = []; + $rootScope.$watchCollection('arrayLikeObject', function logger(obj) { + forEach(obj, function (element){ + arrayLikelog.push(element.name); + }) + }); + document.body.innerHTML = "
"; + + $rootScope.arrayLikeObject = document.getElementsByTagName('a') + $rootScope.$digest(); + expect(arrayLikelog).toEqual(['x', 'y']); + }); }); -- cgit v1.2.3