From 31c56f540045b5270f5b8e235873da855caf3486 Mon Sep 17 00:00:00 2001 From: jankuca Date: Tue, 24 Sep 2013 13:51:28 -0700 Subject: fix(ngRepeat): correctly track elements even when the collection is initially undefined Previously if the collection model was set to undefined on the first digest, the repeater would get confused and not use the correct tracking function for associating model with dom elements in the repeater. Closes #4145 Closes #3964 --- test/ng/directive/ngRepeatSpec.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'test/ng/directive') diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index fc41bc6d..72035566 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -841,6 +841,26 @@ describe('ngRepeat', function() { expect(newLis[1]).toEqual(lis[0]); expect(newLis[2]).toEqual(lis[1]); }); + + it('should be stable even if the collection is initially undefined', function () { + scope.items = undefined; + scope.$digest(); + + scope.items = [ + { name: 'A' }, + { name: 'B' }, + { name: 'C' } + ]; + scope.$digest(); + + lis = element.find('li'); + scope.items.shift(); + scope.$digest(); + + var newLis = element.find('li'); + expect(newLis.length).toBe(2); + expect(newLis[0]).toBe(lis[1]); + }); }); it('should grow multi-node repeater', inject(function($compile, $rootScope) { @@ -861,8 +881,6 @@ describe('ngRepeat', function() { $rootScope.$digest(); expect(element.text()).toEqual('T1:D1;T2:D2;T3:D3;'); })); - - }); describe('ngRepeat animations', function() { -- cgit v1.2.3