test(ngRepeat): clean up and improve tests

This commit is contained in:
Igor Minar 2012-11-23 16:08:47 +01:00
parent d644dcfa52
commit c8e9105fe6

View file

@ -1,7 +1,13 @@
'use strict'; 'use strict';
describe('ngRepeat', function() { describe('ngRepeat', function() {
var element; var element, $compile, scope;
beforeEach(inject(function(_$compile_, $rootScope) {
$compile = _$compile_;
scope = $rootScope.$new();
}));
afterEach(function(){ afterEach(function(){
@ -9,130 +15,131 @@ describe('ngRepeat', function() {
}); });
it('should ngRepeat over array', inject(function($rootScope, $compile) { it('should iterate over an array of objects', function() {
element = $compile( element = $compile(
'<ul>' + '<ul>' +
'<li ng-repeat="item in items" ng-init="suffix = \';\'" ng-bind="item + suffix"></li>' + '<li ng-repeat="item in items">{{item.name}};</li>' +
'</ul>')($rootScope); '</ul>')(scope);
Array.prototype.extraProperty = "should be ignored"; Array.prototype.extraProperty = "should be ignored";
// INIT // INIT
$rootScope.items = ['misko', 'shyam']; scope.items = [{name: 'misko'}, {name:'shyam'}];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(2); expect(element.find('li').length).toEqual(2);
expect(element.text()).toEqual('misko;shyam;'); expect(element.text()).toEqual('misko;shyam;');
delete Array.prototype.extraProperty; delete Array.prototype.extraProperty;
// GROW // GROW
$rootScope.items = ['adam', 'kai', 'brad']; scope.items.push({name: 'adam'});
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('adam;kai;brad;'); expect(element.text()).toEqual('misko;shyam;adam;');
// SHRINK // SHRINK
$rootScope.items = ['brad']; scope.items.pop();
$rootScope.$digest(); scope.items.shift();
scope.$digest();
expect(element.find('li').length).toEqual(1); expect(element.find('li').length).toEqual(1);
expect(element.text()).toEqual('brad;'); expect(element.text()).toEqual('shyam;');
})); });
it('should ngRepeat over array of primitives', inject(function($rootScope, $compile) { it('should iterate over an array of primitives', function() {
element = $compile( element = $compile(
'<ul>' + '<ul>' +
'<li ng-repeat="item in items">{{item}};</li>' + '<li ng-repeat="item in items">{{item}};</li>' +
'</ul>')($rootScope); '</ul>')(scope);
Array.prototype.extraProperty = "should be ignored"; Array.prototype.extraProperty = "should be ignored";
// INIT // INIT
$rootScope.items = [true, true, true]; scope.items = [true, true, true];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('true;true;true;'); expect(element.text()).toEqual('true;true;true;');
delete Array.prototype.extraProperty; delete Array.prototype.extraProperty;
$rootScope.items = [false, true, true]; scope.items = [false, true, true];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('false;true;true;'); expect(element.text()).toEqual('false;true;true;');
$rootScope.items = [false, true, false]; scope.items = [false, true, false];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('false;true;false;'); expect(element.text()).toEqual('false;true;false;');
$rootScope.items = [true]; scope.items = [true];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(1); expect(element.find('li').length).toEqual(1);
expect(element.text()).toEqual('true;'); expect(element.text()).toEqual('true;');
$rootScope.items = [true, true, false]; scope.items = [true, true, false];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('true;true;false;'); expect(element.text()).toEqual('true;true;false;');
$rootScope.items = [true, false, false]; scope.items = [true, false, false];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('true;false;false;'); expect(element.text()).toEqual('true;false;false;');
// string // string
$rootScope.items = ['a', 'a', 'a']; scope.items = ['a', 'a', 'a'];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('a;a;a;'); expect(element.text()).toEqual('a;a;a;');
$rootScope.items = ['ab', 'a', 'a']; scope.items = ['ab', 'a', 'a'];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('ab;a;a;'); expect(element.text()).toEqual('ab;a;a;');
$rootScope.items = ['test']; scope.items = ['test'];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(1); expect(element.find('li').length).toEqual(1);
expect(element.text()).toEqual('test;'); expect(element.text()).toEqual('test;');
$rootScope.items = ['same', 'value']; scope.items = ['same', 'value'];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(2); expect(element.find('li').length).toEqual(2);
expect(element.text()).toEqual('same;value;'); expect(element.text()).toEqual('same;value;');
// number // number
$rootScope.items = [12, 12, 12]; scope.items = [12, 12, 12];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('12;12;12;'); expect(element.text()).toEqual('12;12;12;');
$rootScope.items = [53, 12, 27]; scope.items = [53, 12, 27];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('53;12;27;'); expect(element.text()).toEqual('53;12;27;');
$rootScope.items = [89]; scope.items = [89];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(1); expect(element.find('li').length).toEqual(1);
expect(element.text()).toEqual('89;'); expect(element.text()).toEqual('89;');
$rootScope.items = [89, 23]; scope.items = [89, 23];
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(2); expect(element.find('li').length).toEqual(2);
expect(element.text()).toEqual('89;23;'); expect(element.text()).toEqual('89;23;');
})); });
it('should ngRepeat over object', inject(function($rootScope, $compile) { it('should iterate over on object/map', function() {
element = $compile( element = $compile(
'<ul>' + '<ul>' +
'<li ng-repeat="(key, value) in items" ng-bind="key + \':\' + value + \';\' "></li>' + '<li ng-repeat="(key, value) in items">{{key}}:{{value}}|</li>' +
'</ul>')($rootScope); '</ul>')(scope);
$rootScope.items = {misko:'swe', shyam:'set'}; scope.items = {misko:'swe', shyam:'set'};
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('misko:swe;shyam:set;'); expect(element.text()).toEqual('misko:swe|shyam:set|');
})); });
it('should ngRepeat over object with changing primitive value', it('should iterate over object with changing primitive property values', function() {
inject(function($rootScope, $compile) { // test for issue #933
element = $compile( element = $compile(
'<ul>' + '<ul>' +
@ -140,10 +147,10 @@ describe('ngRepeat', function() {
'{{key}}:{{value}};' + '{{key}}:{{value}};' +
'<input type="checkbox" ng-model="items[key]">' + '<input type="checkbox" ng-model="items[key]">' +
'</li>' + '</li>' +
'</ul>')($rootScope); '</ul>')(scope);
$rootScope.items = {misko: true, shyam: true, zhenbo:true}; scope.items = {misko: true, shyam: true, zhenbo:true};
$rootScope.$digest(); scope.$digest();
expect(element.find('li').length).toEqual(3); expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('misko:true;shyam:true;zhenbo:true;'); expect(element.text()).toEqual('misko:true;shyam:true;zhenbo:true;');
@ -166,216 +173,214 @@ describe('ngRepeat', function() {
expect(element.find('input')[1].checked).toBe(false); expect(element.find('input')[1].checked).toBe(false);
expect(element.find('input')[2].checked).toBe(true); expect(element.find('input')[2].checked).toBe(true);
$rootScope.items = {misko: false, shyam: true, zhenbo: true}; scope.items = {misko: false, shyam: true, zhenbo: true};
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('misko:false;shyam:true;zhenbo:true;'); expect(element.text()).toEqual('misko:false;shyam:true;zhenbo:true;');
expect(element.find('input')[0].checked).toBe(false); expect(element.find('input')[0].checked).toBe(false);
expect(element.find('input')[1].checked).toBe(true); expect(element.find('input')[1].checked).toBe(true);
expect(element.find('input')[2].checked).toBe(true); expect(element.find('input')[2].checked).toBe(true);
})); });
it('should not ngRepeat over parent properties', inject(function($rootScope, $compile) { it('should not ngRepeat over parent properties', function() {
var Class = function() {}; var Class = function() {};
Class.prototype.abc = function() {}; Class.prototype.abc = function() {};
Class.prototype.value = 'abc'; Class.prototype.value = 'abc';
element = $compile( element = $compile(
'<ul>' + '<ul>' +
'<li ng-repeat="(key, value) in items" ng-bind="key + \':\' + value + \';\' "></li>' + '<li ng-repeat="(key, value) in items">{{key}}:{{value}};</li>' +
'</ul>')($rootScope); '</ul>')(scope);
$rootScope.items = new Class(); scope.items = new Class();
$rootScope.items.name = 'value'; scope.items.name = 'value';
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('name:value;'); expect(element.text()).toEqual('name:value;');
})); });
it('should error on wrong parsing of ngRepeat', inject(function($rootScope, $compile) { it('should error on wrong parsing of ngRepeat', function() {
expect(function() { expect(function() {
element = $compile('<ul><li ng-repeat="i dont parse"></li></ul>')($rootScope); element = jqLite('<ul><li ng-repeat="i dont parse"></li></ul>');
$compile(element)(scope);
}).toThrow("Expected ngRepeat in form of '_item_ in _collection_' but got 'i dont parse'."); }).toThrow("Expected ngRepeat in form of '_item_ in _collection_' but got 'i dont parse'.");
})); });
it("should throw error when left-hand-side of ngRepeat can't be parsed", inject( it("should throw error when left-hand-side of ngRepeat can't be parsed", function() {
function($rootScope, $compile) {
expect(function() { expect(function() {
element = $compile('<ul><li ng-repeat="i dont parse in foo"></li></ul>')($rootScope); element = jqLite('<ul><li ng-repeat="i dont parse in foo"></li></ul>');
$compile(element)(scope);
}).toThrow("'item' in 'item in collection' should be identifier or (key, value) but got " + }).toThrow("'item' in 'item in collection' should be identifier or (key, value) but got " +
"'i dont parse'."); "'i dont parse'.");
})); });
it('should expose iterator offset as $index when iterating over arrays', it('should expose iterator offset as $index when iterating over arrays',
inject(function($rootScope, $compile) { function() {
element = $compile( element = $compile(
'<ul>' + '<ul>' +
'<li ng-repeat="item in items" ng-bind="item + $index + \'|\'"></li>' + '<li ng-repeat="item in items">{{item}}:{{$index}}|</li>' +
'</ul>')($rootScope); '</ul>')(scope);
$rootScope.items = ['misko', 'shyam', 'frodo']; scope.items = ['misko', 'shyam', 'frodo'];
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('misko0|shyam1|frodo2|'); expect(element.text()).toEqual('misko:0|shyam:1|frodo:2|');
})); });
it('should expose iterator offset as $index when iterating over objects', it('should expose iterator offset as $index when iterating over objects', function() {
inject(function($rootScope, $compile) {
element = $compile( element = $compile(
'<ul>' + '<ul>' +
'<li ng-repeat="(key, val) in items" ng-bind="key + \':\' + val + $index + \'|\'"></li>' + '<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$index}}|</li>' +
'</ul>')($rootScope); '</ul>')(scope);
$rootScope.items = {'misko':'m', 'shyam':'s', 'frodo':'f'}; scope.items = {'misko':'m', 'shyam':'s', 'frodo':'f'};
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('frodo:f0|misko:m1|shyam:s2|'); expect(element.text()).toEqual('frodo:f:0|misko:m:1|shyam:s:2|');
})); });
it('should expose iterator position as $first, $middle and $last when iterating over arrays', it('should expose iterator position as $first, $middle and $last when iterating over arrays',
inject(function($rootScope, $compile) { function() {
element = $compile( element = $compile(
'<ul>' + '<ul>' +
'<li ng-repeat="item in items">{{item}}:{{$first}}-{{$middle}}-{{$last}}|</li>' + '<li ng-repeat="item in items">{{item}}:{{$first}}-{{$middle}}-{{$last}}|</li>' +
'</ul>')($rootScope); '</ul>')(scope);
$rootScope.items = ['misko', 'shyam', 'doug']; scope.items = ['misko', 'shyam', 'doug'];
$rootScope.$digest(); scope.$digest();
expect(element.text()). expect(element.text()).
toEqual('misko:true-false-false|shyam:false-true-false|doug:false-false-true|'); toEqual('misko:true-false-false|shyam:false-true-false|doug:false-false-true|');
$rootScope.items.push('frodo'); scope.items.push('frodo');
$rootScope.$digest(); scope.$digest();
expect(element.text()). expect(element.text()).
toEqual('misko:true-false-false|' + toEqual('misko:true-false-false|' +
'shyam:false-true-false|' + 'shyam:false-true-false|' +
'doug:false-true-false|' + 'doug:false-true-false|' +
'frodo:false-false-true|'); 'frodo:false-false-true|');
$rootScope.items.pop(); scope.items.pop();
$rootScope.items.pop(); scope.items.pop();
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('misko:true-false-false|shyam:false-false-true|'); expect(element.text()).toEqual('misko:true-false-false|shyam:false-false-true|');
$rootScope.items.pop(); scope.items.pop();
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('misko:true-false-true|'); expect(element.text()).toEqual('misko:true-false-true|');
})); });
it('should expose iterator position as $first, $middle and $last when iterating over objects', it('should expose iterator position as $first, $middle and $last when iterating over objects',
inject(function($rootScope, $compile) { function() {
element = $compile( element = $compile(
'<ul>' + '<ul>' +
'<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$first}}-{{$middle}}-{{$last}}|</li>' + '<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$first}}-{{$middle}}-{{$last}}|</li>' +
'</ul>')($rootScope); '</ul>')(scope);
$rootScope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'}; scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'};
$rootScope.$digest(); scope.$digest();
expect(element.text()). expect(element.text()).
toEqual('doug:d:true-false-false|' + toEqual('doug:d:true-false-false|' +
'frodo:f:false-true-false|' + 'frodo:f:false-true-false|' +
'misko:m:false-true-false|' + 'misko:m:false-true-false|' +
'shyam:s:false-false-true|'); 'shyam:s:false-false-true|');
delete $rootScope.items.doug; delete scope.items.doug;
delete $rootScope.items.frodo; delete scope.items.frodo;
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('misko:m:true-false-false|shyam:s:false-false-true|'); expect(element.text()).toEqual('misko:m:true-false-false|shyam:s:false-false-true|');
delete $rootScope.items.shyam; delete scope.items.shyam;
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('misko:m:true-false-true|'); expect(element.text()).toEqual('misko:m:true-false-true|');
})); });
it('should ignore $ and $$ properties', inject(function($rootScope, $compile) { it('should ignore $ and $$ properties', function() {
element = $compile('<ul><li ng-repeat="i in items">{{i}}|</li></ul>')($rootScope); element = $compile('<ul><li ng-repeat="i in items">{{i}}|</li></ul>')(scope);
$rootScope.items = ['a', 'b', 'c']; scope.items = ['a', 'b', 'c'];
$rootScope.items.$$hashkey = 'xxx'; scope.items.$$hashkey = 'xxx';
$rootScope.items.$root = 'yyy'; scope.items.$root = 'yyy';
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('a|b|c|'); expect(element.text()).toEqual('a|b|c|');
})); });
it('should repeat over nested arrays', inject(function($rootScope, $compile) { it('should repeat over nested arrays', function() {
element = $compile( element = $compile(
'<ul>' + '<ul>' +
'<li ng-repeat="subgroup in groups">' + '<li ng-repeat="subgroup in groups">' +
'<div ng-repeat="group in subgroup">{{group}}|</div>X' + '<div ng-repeat="group in subgroup">{{group}}|</div>X' +
'</li>' + '</li>' +
'</ul>')($rootScope); '</ul>')(scope);
$rootScope.groups = [['a', 'b'], ['c','d']]; scope.groups = [['a', 'b'], ['c','d']];
$rootScope.$digest(); scope.$digest();
expect(element.text()).toEqual('a|b|Xc|d|X'); expect(element.text()).toEqual('a|b|Xc|d|X');
})); });
it('should ignore non-array element properties when iterating over an array', it('should ignore non-array element properties when iterating over an array', function() {
inject(function($rootScope, $compile) { element = $compile('<ul><li ng-repeat="item in array">{{item}}|</li></ul>')(scope);
element = $compile('<ul><li ng-repeat="item in array">{{item}}|</li></ul>')($rootScope); scope.array = ['a', 'b', 'c'];
$rootScope.array = ['a', 'b', 'c']; scope.array.foo = '23';
$rootScope.array.foo = '23'; scope.array.bar = function() {};
$rootScope.array.bar = function() {}; scope.$digest();
$rootScope.$digest();
expect(element.text()).toBe('a|b|c|'); expect(element.text()).toBe('a|b|c|');
})); });
it('should iterate over non-existent elements of a sparse array', it('should iterate over non-existent elements of a sparse array', function() {
inject(function($rootScope, $compile) { element = $compile('<ul><li ng-repeat="item in array">{{item}}|</li></ul>')(scope);
element = $compile('<ul><li ng-repeat="item in array">{{item}}|</li></ul>')($rootScope); scope.array = ['a', 'b'];
$rootScope.array = ['a', 'b']; scope.array[4] = 'c';
$rootScope.array[4] = 'c'; scope.array[6] = 'd';
$rootScope.array[6] = 'd'; scope.$digest();
$rootScope.$digest();
expect(element.text()).toBe('a|b|||c||d|'); expect(element.text()).toBe('a|b|||c||d|');
})); });
it('should iterate over all kinds of types', inject(function($rootScope, $compile) { it('should iterate over all kinds of types', function() {
element = $compile('<ul><li ng-repeat="item in array">{{item}}|</li></ul>')($rootScope); element = $compile('<ul><li ng-repeat="item in array">{{item}}|</li></ul>')(scope);
$rootScope.array = ['a', 1, null, undefined, {}]; scope.array = ['a', 1, null, undefined, {}];
$rootScope.$digest(); scope.$digest();
expect(element.text()).toMatch(/a\|1\|\|\|\{\s*\}\|/); expect(element.text()).toMatch(/a\|1\|\|\|\{\s*\}\|/);
})); });
describe('stability', function() { describe('stability', function() {
var a, b, c, d, lis; var a, b, c, d, lis;
beforeEach(inject(function($rootScope, $compile) { beforeEach(function() {
element = $compile( element = $compile(
'<ul>' + '<ul>' +
'<li ng-repeat="item in items">{{key}}:{{val}}|></li>' + '<li ng-repeat="item in items">{{key}}:{{val}}|></li>' +
'</ul>')($rootScope); '</ul>')(scope);
a = {}; a = {};
b = {}; b = {};
c = {}; c = {};
d = {}; d = {};
$rootScope.items = [a, b, c]; scope.items = [a, b, c];
$rootScope.$digest(); scope.$digest();
lis = element.find('li'); lis = element.find('li');
})); });
it('should preserve the order of elements', inject(function($rootScope) { it('should preserve the order of elements', function() {
$rootScope.items = [a, c, d]; scope.items = [a, c, d];
$rootScope.$digest(); scope.$digest();
var newElements = element.find('li'); var newElements = element.find('li');
expect(newElements[0]).toEqual(lis[0]); expect(newElements[0]).toEqual(lis[0]);
expect(newElements[1]).toEqual(lis[2]); expect(newElements[1]).toEqual(lis[2]);
expect(newElements[2]).not.toEqual(lis[1]); expect(newElements[2]).not.toEqual(lis[1]);
})); });
it('should support duplicates', inject(function($rootScope) { it('should support duplicates', function() {
$rootScope.items = [a, a, b, c]; scope.items = [a, a, b, c];
$rootScope.$digest(); scope.$digest();
var newElements = element.find('li'); var newElements = element.find('li');
expect(newElements[0]).toEqual(lis[0]); expect(newElements[0]).toEqual(lis[0]);
expect(newElements[1]).not.toEqual(lis[0]); expect(newElements[1]).not.toEqual(lis[0]);
@ -383,50 +388,48 @@ describe('ngRepeat', function() {
expect(newElements[3]).toEqual(lis[2]); expect(newElements[3]).toEqual(lis[2]);
lis = newElements; lis = newElements;
$rootScope.$digest(); scope.$digest();
newElements = element.find('li'); newElements = element.find('li');
expect(newElements[0]).toEqual(lis[0]); expect(newElements[0]).toEqual(lis[0]);
expect(newElements[1]).toEqual(lis[1]); expect(newElements[1]).toEqual(lis[1]);
expect(newElements[2]).toEqual(lis[2]); expect(newElements[2]).toEqual(lis[2]);
expect(newElements[3]).toEqual(lis[3]); expect(newElements[3]).toEqual(lis[3]);
$rootScope.$digest(); scope.$digest();
newElements = element.find('li'); newElements = element.find('li');
expect(newElements[0]).toEqual(lis[0]); expect(newElements[0]).toEqual(lis[0]);
expect(newElements[1]).toEqual(lis[1]); expect(newElements[1]).toEqual(lis[1]);
expect(newElements[2]).toEqual(lis[2]); expect(newElements[2]).toEqual(lis[2]);
expect(newElements[3]).toEqual(lis[3]); expect(newElements[3]).toEqual(lis[3]);
})); });
it('should remove last item when one duplicate instance is removed', it('should remove last item when one duplicate instance is removed', function() {
inject(function($rootScope) { scope.items = [a, a, a];
$rootScope.items = [a, a, a]; scope.$digest();
$rootScope.$digest();
lis = element.find('li'); lis = element.find('li');
$rootScope.items = [a, a]; scope.items = [a, a];
$rootScope.$digest(); scope.$digest();
var newElements = element.find('li'); var newElements = element.find('li');
expect(newElements.length).toEqual(2); expect(newElements.length).toEqual(2);
expect(newElements[0]).toEqual(lis[0]); expect(newElements[0]).toEqual(lis[0]);
expect(newElements[1]).toEqual(lis[1]); expect(newElements[1]).toEqual(lis[1]);
})); });
it('should reverse items when the collection is reversed', it('should reverse items when the collection is reversed', function() {
inject(function($rootScope) { scope.items = [a, b, c];
$rootScope.items = [a, b, c]; scope.$digest();
$rootScope.$digest();
lis = element.find('li'); lis = element.find('li');
$rootScope.items = [c, b, a]; scope.items = [c, b, a];
$rootScope.$digest(); scope.$digest();
var newElements = element.find('li'); var newElements = element.find('li');
expect(newElements.length).toEqual(3); expect(newElements.length).toEqual(3);
expect(newElements[0]).toEqual(lis[2]); expect(newElements[0]).toEqual(lis[2]);
expect(newElements[1]).toEqual(lis[1]); expect(newElements[1]).toEqual(lis[1]);
expect(newElements[2]).toEqual(lis[0]); expect(newElements[2]).toEqual(lis[0]);
})); });
}); });
}); });