aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMax2012-05-02 18:51:31 +0200
committerIgor Minar2012-05-22 14:18:15 -0700
commit1d388676e3b97b6171fc498e82545bd437ee6fd1 (patch)
treea09e472fc4dc0fb03ce0d5d25160f6a8f3f7ce9d /test
parent84542d2431d20de42d6ec27c9d3435dd72dbe2ee (diff)
downloadangular.js-1d388676e3b97b6171fc498e82545bd437ee6fd1.tar.bz2
fix(ngRepeat): expose $first, $middle and $last instead of $position
$position marker doesn't work well in cases when we have just one item in the list because then the item is both the first and last. To solve this properly we need to expose individual $first and $middle and $last flags. BREAKING CHANGE: $position is not exposed in repeater scopes any more To update, search for $position and replace it with one of $first, $middle or $last. Closes #912
Diffstat (limited to 'test')
-rw-r--r--test/ng/directive/ngRepeatSpec.js38
1 files changed, 27 insertions, 11 deletions
diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js
index 5cb7196b..72382591 100644
--- a/test/ng/directive/ngRepeatSpec.js
+++ b/test/ng/directive/ngRepeatSpec.js
@@ -104,42 +104,58 @@ describe('ngRepeat', function() {
}));
- it('should expose iterator position as $position when iterating over arrays',
+ it('should expose iterator position as $first, $middle and $last when iterating over arrays',
inject(function($rootScope, $compile) {
element = $compile(
'<ul>' +
- '<li ng-repeat="item in items" ng-bind="item + \':\' + $position + \'|\'"></li>' +
+ '<li ng-repeat="item in items">{{item}}:{{$first}}-{{$middle}}-{{$last}}|</li>' +
'</ul>')($rootScope);
$rootScope.items = ['misko', 'shyam', 'doug'];
$rootScope.$digest();
- expect(element.text()).toEqual('misko:first|shyam:middle|doug:last|');
+ expect(element.text()).
+ toEqual('misko:true-false-false|shyam:false-true-false|doug:false-false-true|');
$rootScope.items.push('frodo');
$rootScope.$digest();
- expect(element.text()).toEqual('misko:first|shyam:middle|doug:middle|frodo:last|');
+ expect(element.text()).
+ toEqual('misko:true-false-false|' +
+ 'shyam:false-true-false|' +
+ 'doug:false-true-false|' +
+ 'frodo:false-false-true|');
$rootScope.items.pop();
$rootScope.items.pop();
$rootScope.$digest();
- expect(element.text()).toEqual('misko:first|shyam:last|');
+ expect(element.text()).toEqual('misko:true-false-false|shyam:false-false-true|');
+
+ $rootScope.items.pop();
+ $rootScope.$digest();
+ expect(element.text()).toEqual('misko:true-false-true|');
}));
- it('should expose iterator position as $position when iterating over objects',
+ it('should expose iterator position as $first, $middle and $last when iterating over objects',
inject(function($rootScope, $compile) {
element = $compile(
'<ul>' +
- '<li ng-repeat="(key, val) in items" ng-bind="key + \':\' + val + \':\' + $position + \'|\'">' +
- '</li>' +
+ '<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$first}}-{{$middle}}-{{$last}}|</li>' +
'</ul>')($rootScope);
$rootScope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'};
$rootScope.$digest();
- expect(element.text()).toEqual('doug:d:first|frodo:f:middle|misko:m:middle|shyam:s:last|');
+ expect(element.text()).
+ toEqual('doug:d:true-false-false|' +
+ 'frodo:f:false-true-false|' +
+ 'misko:m:false-true-false|' +
+ 'shyam:s:false-false-true|');
delete $rootScope.items.doug;
delete $rootScope.items.frodo;
$rootScope.$digest();
- expect(element.text()).toEqual('misko:m:first|shyam:s:last|');
+ expect(element.text()).toEqual('misko:m:true-false-false|shyam:s:false-false-true|');
+
+ delete $rootScope.items.shyam;
+ $rootScope.$digest();
+ expect(element.text()).toEqual('misko:m:true-false-true|');
}));
@@ -207,7 +223,7 @@ describe('ngRepeat', function() {
beforeEach(inject(function($rootScope, $compile) {
element = $compile(
'<ul>' +
- '<li ng-repeat="item in items" ng-bind="key + \':\' + val + \':\' + $position + \'|\'"></li>' +
+ '<li ng-repeat="item in items">{{key}}:{{val}}|></li>' +
'</ul>')($rootScope);
a = {};
b = {};