From 1b9277bf6f16f714bba418dd5a7bf719206fe4d6 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Mon, 12 Mar 2012 01:24:43 -0700 Subject: fix(forms): Propagate change from model even if it's undefined --- test/directive/inputSpec.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'test/directive/inputSpec.js') diff --git a/test/directive/inputSpec.js b/test/directive/inputSpec.js index 6298fc64..653dfdc6 100644 --- a/test/directive/inputSpec.js +++ b/test/directive/inputSpec.js @@ -183,22 +183,32 @@ describe('NgModelController', function() { }); - it('should $render only if value changed and is valid', function() { + it('should $render only if value changed', function() { spyOn(ctrl, 'render'); scope.$apply(function() { - scope.value= 3; + scope.value = 3; }); expect(ctrl.render).toHaveBeenCalledOnce(); ctrl.render.reset(); - // invalid - ctrl.formatters.push(function() {return undefined;}); + ctrl.formatters.push(function() {return 3;}); scope.$apply(function() { - scope.value= 5; + scope.value = 5; }); expect(ctrl.render).not.toHaveBeenCalled(); }); + + + it('should clear the view even if invalid', function() { + spyOn(ctrl, 'render'); + + ctrl.formatters.push(function() {return undefined;}); + scope.$apply(function() { + scope.value = 5; + }); + expect(ctrl.render).toHaveBeenCalledOnce(); + }); }); }); @@ -729,6 +739,19 @@ describe('input', function() { browserTrigger(inputElm, 'click'); expect(scope.name).toEqual('n'); }); + + + it('should be required if false', function() { + compileInput(''); + + browserTrigger(inputElm, 'click'); + expect(inputElm[0].checked).toBe(true); + expect(inputElm).toBeValid(); + + browserTrigger(inputElm, 'click'); + expect(inputElm[0].checked).toBe(false); + expect(inputElm).toBeInvalid(); + }); }); -- cgit v1.2.3