From fad626f3047cd4ff31fe7a4181ca63f275adbae6 Mon Sep 17 00:00:00 2001 From: Daniel Herman Date: Thu, 25 Jul 2013 23:15:57 -0400 Subject: fix(isArrayLike) Correctly detect arrayLike items Change the implementation of isArrayLike to use one heavily based on the implementation in jQuery in order to correctly detect array-like objects, that way functionality like ngRepeat works as expected. --- test/ng/directive/ngRepeatSpec.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index a85fd5ab..9dfaa404 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -77,7 +77,27 @@ describe('ngRepeat', function() { expect(element.find('li').length).toEqual(3); expect(element.text()).toEqual('x;y;x;'); }); + + it('should iterate over an array-like class', function() { + function Collection() {} + Collection.prototype = new Array(); + Collection.prototype.length = 0; + var collection = new Collection(); + collection.push({ name: "x" }); + collection.push({ name: "y" }); + collection.push({ name: "z" }); + + element = $compile( + '')(scope); + + scope.items = collection; + scope.$digest(); + expect(element.find('li').length).toEqual(3); + expect(element.text()).toEqual('x;y;z;'); + }); it('should iterate over on object/map', function() { element = $compile( -- cgit v1.2.3