From 22d1464d7abc284dd56d6beaf47e8d85088e01c5 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 13 May 2010 13:57:39 -0700 Subject: fixed issue with radio view clobering model if radio was checked. --- test/widgetsSpec.js | 70 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 21 deletions(-) (limited to 'test/widgetsSpec.js') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 9df024cb..ecea6223 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -8,7 +8,7 @@ describe("widget", function(){ compile = function(html, before) { element = jqLite(html); scope = compiler.compile(element)(element); - (before||noop)(); + (before||noop).apply(scope); scope.$init(); }; }); @@ -222,29 +222,57 @@ describe("widget", function(){ expect(scope.checkbox).toEqual(true); }); - it('should support type="radio"', function(){ - compile('
' + - '' + - '' + - '' + + describe('radio', function(){ + + it('should support type="radio"', function(){ + compile('
' + + '' + + '' + + '' + '
'); - var a = element[0].childNodes[0]; - var b = element[0].childNodes[1]; - expect(b.name.split('@')[1]).toEqual('chose'); - expect(scope.chose).toEqual('B'); - scope.chose = 'A'; - scope.$eval(); - expect(a.checked).toEqual(true); + var a = element[0].childNodes[0]; + var b = element[0].childNodes[1]; + expect(b.name.split('@')[1]).toEqual('chose'); + expect(scope.chose).toEqual('B'); + scope.chose = 'A'; + scope.$eval(); + expect(a.checked).toEqual(true); - scope.chose = 'B'; - scope.$eval(); - expect(a.checked).toEqual(false); - expect(b.checked).toEqual(true); - expect(scope.clicked).not.toBeDefined(); + scope.chose = 'B'; + scope.$eval(); + expect(a.checked).toEqual(false); + expect(b.checked).toEqual(true); + expect(scope.clicked).not.toBeDefined(); + + click(a); + expect(scope.chose).toEqual('A'); + expect(scope.clicked).toEqual(1); + }); + + it('should honor model over html checked keyword after', function(){ + compile('
' + + '' + + '' + + '' + + '
', function(){ + this.choose = 'C'; + }); + + expect(scope.choose).toEqual('C'); + }); + + it('should honor model over html checked keyword before', function(){ + compile('
' + + '' + + '' + + '' + + '
', function(){ + this.choose = 'A'; + }); + + expect(scope.choose).toEqual('A'); + }); - click(a); - expect(scope.chose).toEqual('A'); - expect(scope.clicked).toEqual(1); }); it('should support type="select-one"', function(){ -- cgit v1.2.3