Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
test(ngRepeat): add test for issue #1076
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMinar committed Nov 26, 2012
1 parent 733a97a commit e7d37ee
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions test/ng/directive/ngRepeatSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ describe('ngRepeat', function() {
}));


it('should ngRepeat over array of primitive correctly', inject(function($rootScope, $compile) {
it('should ngRepeat over array of primitives', inject(function($rootScope, $compile) {
element = $compile(
'<ul>' +
'<li ng-repeat="item in items" ng-init="suffix = \';\'" ng-bind="item + suffix"></li>' +
'<li ng-repeat="item in items">{{item}};</li>' +
'</ul>')($rootScope);

Array.prototype.extraProperty = "should be ignored";
Expand Down Expand Up @@ -91,13 +91,13 @@ describe('ngRepeat', function() {
$rootScope.$digest();
expect(element.find('li').length).toEqual(1);
expect(element.text()).toEqual('test;');

$rootScope.items = ['same', 'value'];
$rootScope.$digest();
expect(element.find('li').length).toEqual(2);
expect(element.text()).toEqual('same;value;');
// number

// number
$rootScope.items = [12, 12, 12];
$rootScope.$digest();
expect(element.find('li').length).toEqual(3);
Expand Down Expand Up @@ -130,36 +130,48 @@ describe('ngRepeat', function() {
expect(element.text()).toEqual('misko:swe;shyam:set;');
}));


it('should ngRepeat over object with primitive value correctly', inject(function($rootScope, $compile) {

it('should ngRepeat over object with changing primitive value',
inject(function($rootScope, $compile) {

element = $compile(
'<ul>' +
'<li ng-repeat="(key, value) in items" ng-bind="key + \':\' + value + \';\' "></li>' +
'<li ng-repeat="(key, value) in items">' +
'{{key}}:{{value}};' +
'<input type="checkbox" ng-model="items[key]">' +
'</li>' +
'</ul>')($rootScope);
$rootScope.items = {misko:'true', shyam:'true', zhenbo: 'true'};

$rootScope.items = {misko: true, shyam: true, zhenbo:true};
$rootScope.$digest();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('misko:true;shyam:true;zhenbo:true;');

$rootScope.items = {misko:'false', shyam:'true', zhenbo: 'true'};
$rootScope.$digest();
expect(element.find('li').length).toEqual(3);

browserTrigger(element.find('input').eq(0), 'click');

expect(element.text()).toEqual('misko:false;shyam:true;zhenbo:true;');

$rootScope.items = {misko:'false', shyam:'false', zhenbo: 'false'};
$rootScope.$digest();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('misko:false;shyam:false;zhenbo:false;');

$rootScope.items = {misko:'true'};
$rootScope.$digest();
expect(element.find('li').length).toEqual(1);
expect(element.text()).toEqual('misko:true;');
expect(element.find('input')[0].checked).toBe(false);
expect(element.find('input')[1].checked).toBe(true);
expect(element.find('input')[2].checked).toBe(true);

$rootScope.items = {shyam:'true', zhenbo: 'false'};
browserTrigger(element.find('input').eq(0), 'click');
expect(element.text()).toEqual('misko:true;shyam:true;zhenbo:true;');
expect(element.find('input')[0].checked).toBe(true);
expect(element.find('input')[1].checked).toBe(true);
expect(element.find('input')[2].checked).toBe(true);

browserTrigger(element.find('input').eq(1), 'click');
expect(element.text()).toEqual('misko:true;shyam:false;zhenbo:true;');
expect(element.find('input')[0].checked).toBe(true);
expect(element.find('input')[1].checked).toBe(false);
expect(element.find('input')[2].checked).toBe(true);

$rootScope.items = {misko: false, shyam: true, zhenbo: true};
$rootScope.$digest();
expect(element.find('li').length).toEqual(2);
expect(element.text()).toEqual('shyam:true;zhenbo:false;');
expect(element.text()).toEqual('misko:false;shyam:true;zhenbo:true;');
expect(element.find('input')[0].checked).toBe(false);
expect(element.find('input')[1].checked).toBe(true);
expect(element.find('input')[2].checked).toBe(true);
}));


Expand Down

0 comments on commit e7d37ee

Please sign in to comment.