From e7d37ee45ac48b0ff2a3d43f7236d316be6c241e Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 26 Nov 2012 20:17:11 +0100 Subject: [PATCH] test(ngRepeat): add test for issue #1076 --- test/ng/directive/ngRepeatSpec.js | 64 ++++++++++++++++++------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 83f23cec370d..49c009defa3b 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -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( '')($rootScope); Array.prototype.extraProperty = "should be ignored"; @@ -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); @@ -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( '')($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); }));