From 58ac2683aab69afabca5b62d83a73017397fb474 Mon Sep 17 00:00:00 2001 From: Joe Enzminger Date: Wed, 8 Jan 2014 09:18:40 -0600 Subject: [PATCH 1/4] bug($ng): change numberInputType to check for leading decimals add check for leading decimal. Some browsers swallow leading decimals on input type="number". fixes #5680 --- src/ng/directive/input.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 4e77397878dd..6df1b05c7150 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -534,6 +534,10 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) { textInputType(scope, element, attr, ctrl, $sniffer, $browser); ctrl.$parsers.push(function(value) { + //on some browsers, '.' evaluates to NaN which prevents input of leading decimals + if (value === '.') { + value = '0.'; + } var empty = ctrl.$isEmpty(value); if (empty || NUMBER_REGEXP.test(value)) { ctrl.$setValidity('number', true); From 8370fc76fa0dca8d3972abd8431d2e18019d5b53 Mon Sep 17 00:00:00 2001 From: Joe Enzminger Date: Thu, 9 Jan 2014 09:33:37 -0600 Subject: [PATCH 2/4] added unit test for issue 5680 --- test/ng/directive/inputSpec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 26abceae1cfe..60531ca9b5cc 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -815,6 +815,14 @@ describe('input', function() { expect(inputElm).toBeValid(); }); + it('should parse "." to zero', function () { + compileInput(''); + changeInputValueTo('.'); + expect(scope.price).toBe(0); + expect(inputElm).toBeValid(); + expect(inputElm.val()).toBe('.'); + }); + describe('min', function() { From 2aa80e88c4aee13bc067e808065da97373e967ca Mon Sep 17 00:00:00 2001 From: Joe Enzminger Date: Thu, 9 Jan 2014 09:42:19 -0600 Subject: [PATCH 3/4] modified unit test to be more specific --- test/ng/directive/inputSpec.js | 1496 ++++++++++++++++---------------- 1 file changed, 748 insertions(+), 748 deletions(-) diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 60531ca9b5cc..876941c66812 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -409,1072 +409,1072 @@ describe('ngModel', function() { }); -describe('input', function() { - var formElm, inputElm, scope, $compile, $sniffer, $browser, changeInputValueTo; - - function compileInput(inputHtml) { - inputElm = jqLite(inputHtml); - formElm = jqLite('
'); - formElm.append(inputElm); - $compile(formElm)(scope); - } - - beforeEach(inject(function($injector, _$sniffer_, _$browser_) { - $sniffer = _$sniffer_; - $browser = _$browser_; - $compile = $injector.get('$compile'); - scope = $injector.get('$rootScope'); - - changeInputValueTo = function(value) { - inputElm.val(value); - browserTrigger(inputElm, $sniffer.hasEvent('input') ? 'input' : 'change'); - }; - })); - - afterEach(function() { - dealoc(formElm); - }); +describe('input', function () { + var formElm, inputElm, scope, $compile, $sniffer, $browser, changeInputValueTo; + + function compileInput(inputHtml) { + inputElm = jqLite(inputHtml); + formElm = jqLite('
'); + formElm.append(inputElm); + $compile(formElm)(scope); + } + beforeEach(inject(function ($injector, _$sniffer_, _$browser_) { + $sniffer = _$sniffer_; + $browser = _$browser_; + $compile = $injector.get('$compile'); + scope = $injector.get('$rootScope'); - it('should bind to a model', function() { - compileInput(''); + changeInputValueTo = function (value) { + inputElm.val(value); + browserTrigger(inputElm, $sniffer.hasEvent('input') ? 'input' : 'change'); + }; + })); - scope.$apply(function() { - scope.name = 'misko'; + afterEach(function () { + dealoc(formElm); }); - expect(inputElm.val()).toBe('misko'); - }); + it('should bind to a model', function () { + compileInput(''); - it('should not set readonly or disabled property on ie7', function() { - this.addMatchers({ - toBeOff: function(attributeName) { - var actualValue = this.actual.attr(attributeName); - this.message = function() { - return "Attribute '" + attributeName + "' expected to be off but was '" + actualValue + - "' in: " + angular.mock.dump(this.actual); - } + scope.$apply(function () { + scope.name = 'misko'; + }); - return !actualValue || actualValue == 'false'; - } + expect(inputElm.val()).toBe('misko'); }); - compileInput(''); - expect(inputElm.prop('readOnly')).toBe(false); - expect(inputElm.prop('disabled')).toBe(false); - expect(inputElm).toBeOff('readOnly'); - expect(inputElm).toBeOff('readonly'); - expect(inputElm).toBeOff('disabled'); - }); + it('should not set readonly or disabled property on ie7', function () { + this.addMatchers({ + toBeOff: function (attributeName) { + var actualValue = this.actual.attr(attributeName); + this.message = function () { + return "Attribute '" + attributeName + "' expected to be off but was '" + actualValue + + "' in: " + angular.mock.dump(this.actual); + } + return !actualValue || actualValue == 'false'; + } + }); - it('should update the model on "blur" event', function() { - compileInput(''); + compileInput(''); + expect(inputElm.prop('readOnly')).toBe(false); + expect(inputElm.prop('disabled')).toBe(false); - changeInputValueTo('adam'); - expect(scope.name).toEqual('adam'); - }); - - if (!(msie < 9)) { - describe('compositionevents', function() { - it('should not update the model between "compositionstart" and "compositionend" on non android', inject(function($sniffer) { - $sniffer.android = false; + expect(inputElm).toBeOff('readOnly'); + expect(inputElm).toBeOff('readonly'); + expect(inputElm).toBeOff('disabled'); + }); - compileInput(''); - changeInputValueTo('a'); - expect(scope.name).toEqual('a'); - browserTrigger(inputElm, 'compositionstart'); - changeInputValueTo('adam'); - expect(scope.name).toEqual('a'); - browserTrigger(inputElm, 'compositionend'); - changeInputValueTo('adam'); - expect(scope.name).toEqual('adam'); - })); - it('should update the model between "compositionstart" and "compositionend" on android', inject(function($sniffer) { - $sniffer.android = true; + it('should update the model on "blur" event', function () { + compileInput(''); - compileInput(''); - changeInputValueTo('a'); - expect(scope.name).toEqual('a'); - browserTrigger(inputElm, 'compositionstart'); changeInputValueTo('adam'); expect(scope.name).toEqual('adam'); - browserTrigger(inputElm, 'compositionend'); - changeInputValueTo('adam2'); - expect(scope.name).toEqual('adam2'); - })); }); - } - - describe('"change" event', function() { - function assertBrowserSupportsChangeEvent(inputEventSupported) { - // Force browser to report a lack of an 'input' event - $sniffer.hasEvent = function(eventName) { - if (eventName === 'input' && !inputEventSupported) { - return false; - } - return true; - }; - compileInput(''); - inputElm.val('mark'); - browserTrigger(inputElm, 'change'); - expect(scope.name).toEqual('mark'); + if (!(msie < 9)) { + describe('compositionevents', function () { + it('should not update the model between "compositionstart" and "compositionend" on non android', inject(function ($sniffer) { + $sniffer.android = false; + + compileInput(''); + changeInputValueTo('a'); + expect(scope.name).toEqual('a'); + browserTrigger(inputElm, 'compositionstart'); + changeInputValueTo('adam'); + expect(scope.name).toEqual('a'); + browserTrigger(inputElm, 'compositionend'); + changeInputValueTo('adam'); + expect(scope.name).toEqual('adam'); + })); + + it('should update the model between "compositionstart" and "compositionend" on android', inject(function ($sniffer) { + $sniffer.android = true; + + compileInput(''); + changeInputValueTo('a'); + expect(scope.name).toEqual('a'); + browserTrigger(inputElm, 'compositionstart'); + changeInputValueTo('adam'); + expect(scope.name).toEqual('adam'); + browserTrigger(inputElm, 'compositionend'); + changeInputValueTo('adam2'); + expect(scope.name).toEqual('adam2'); + })); + }); } - it('should update the model event if the browser does not support the "input" event',function() { - assertBrowserSupportsChangeEvent(false); - }); + describe('"change" event', function () { + function assertBrowserSupportsChangeEvent(inputEventSupported) { + // Force browser to report a lack of an 'input' event + $sniffer.hasEvent = function (eventName) { + if (eventName === 'input' && !inputEventSupported) { + return false; + } + return true; + }; + compileInput(''); + + inputElm.val('mark'); + browserTrigger(inputElm, 'change'); + expect(scope.name).toEqual('mark'); + } - it('should update the model event if the browser supports the "input" ' + - 'event so that form auto complete works',function() { - assertBrowserSupportsChangeEvent(true); - }); + it('should update the model event if the browser does not support the "input" event', function () { + assertBrowserSupportsChangeEvent(false); + }); - if (!_jqLiteMode) { - it('should not cause the double $digest when triggering an event using jQuery', function() { - $sniffer.hasEvent = function(eventName) { - return eventName !== 'input'; - }; + it('should update the model event if the browser supports the "input" ' + + 'event so that form auto complete works', function () { + assertBrowserSupportsChangeEvent(true); + }); - compileInput(''); + if (!_jqLiteMode) { + it('should not cause the double $digest when triggering an event using jQuery', function () { + $sniffer.hasEvent = function (eventName) { + return eventName !== 'input'; + }; + + compileInput(''); + + scope.field = 'fake field'; + scope.$watch('field', function () { + // We need to use _originalTrigger since trigger is modified by Angular Scenario. + inputElm._originalTrigger('change'); + }); + scope.$apply(); + }); + } + }); - scope.field = 'fake field'; - scope.$watch('field', function() { - // We need to use _originalTrigger since trigger is modified by Angular Scenario. - inputElm._originalTrigger('change'); + describe('"paste" and "cut" events', function () { + beforeEach(function () { + // Force browser to report a lack of an 'input' event + $sniffer.hasEvent = function (eventName) { + return eventName !== 'input'; + }; }); - scope.$apply(); - }); - } - }); - describe('"paste" and "cut" events', function() { - beforeEach(function() { - // Force browser to report a lack of an 'input' event - $sniffer.hasEvent = function(eventName) { - return eventName !== 'input'; - }; - }); + it('should update the model on "paste" event', function () { + compileInput(''); - it('should update the model on "paste" event', function() { - compileInput(''); + inputElm.val('mark'); + browserTrigger(inputElm, 'paste'); + $browser.defer.flush(); + expect(scope.name).toEqual('mark'); + }); - inputElm.val('mark'); - browserTrigger(inputElm, 'paste'); - $browser.defer.flush(); - expect(scope.name).toEqual('mark'); - }); + it('should update the model on "cut" event', function () { + compileInput(''); - it('should update the model on "cut" event', function() { - compileInput(''); + inputElm.val('john'); + browserTrigger(inputElm, 'cut'); + $browser.defer.flush(); + expect(scope.name).toEqual('john'); + }); - inputElm.val('john'); - browserTrigger(inputElm, 'cut'); - $browser.defer.flush(); - expect(scope.name).toEqual('john'); }); - }); - - it('should update the model and trim the value', function() { - compileInput(''); + it('should update the model and trim the value', function () { + compileInput(''); - changeInputValueTo(' a '); - expect(scope.name).toEqual('a'); - }); + changeInputValueTo(' a '); + expect(scope.name).toEqual('a'); + }); - it('should update the model and not trim the value', function() { - compileInput(''); + it('should update the model and not trim the value', function () { + compileInput(''); - changeInputValueTo(' a '); - expect(scope.name).toEqual(' a '); - }); + changeInputValueTo(' a '); + expect(scope.name).toEqual(' a '); + }); - it('should allow complex reference binding', function() { - compileInput(''); + it('should allow complex reference binding', function () { + compileInput(''); - scope.$apply(function() { - scope.obj = { abc: { name: 'Misko'} }; + scope.$apply(function () { + scope.obj = { abc: { name: 'Misko'} }; + }); + expect(inputElm.val()).toEqual('Misko'); }); - expect(inputElm.val()).toEqual('Misko'); - }); - it('should ignore input without ngModel directive', function() { - compileInput(''); + it('should ignore input without ngModel directive', function () { + compileInput(''); - changeInputValueTo(''); - expect(inputElm.hasClass('ng-valid')).toBe(false); - expect(inputElm.hasClass('ng-invalid')).toBe(false); - expect(inputElm.hasClass('ng-pristine')).toBe(false); - expect(inputElm.hasClass('ng-dirty')).toBe(false); - }); + changeInputValueTo(''); + expect(inputElm.hasClass('ng-valid')).toBe(false); + expect(inputElm.hasClass('ng-invalid')).toBe(false); + expect(inputElm.hasClass('ng-pristine')).toBe(false); + expect(inputElm.hasClass('ng-dirty')).toBe(false); + }); - it('should report error on assignment error', function() { - expect(function() { - compileInput(''); - scope.$digest(); - }).toThrowMinErr("$parse", "syntax", "Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw ''] starting at ['']."); - }); + it('should report error on assignment error', function () { + expect(function () { + compileInput(''); + scope.$digest(); + }).toThrowMinErr("$parse", "syntax", "Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw ''] starting at ['']."); + }); + + it("should render as blank if null", function () { + compileInput(''); - it("should render as blank if null", function() { - compileInput(''); + scope.$apply(function () { + scope.age = null; + }); - scope.$apply(function() { - scope.age = null; + expect(scope.age).toBeNull(); + expect(inputElm.val()).toEqual(''); }); - expect(scope.age).toBeNull(); - expect(inputElm.val()).toEqual(''); - }); + it('should render 0 even if it is a number', function () { + compileInput(''); + scope.$apply(function () { + scope.value = 0; + }); - it('should render 0 even if it is a number', function() { - compileInput(''); - scope.$apply(function() { - scope.value = 0; + expect(inputElm.val()).toBe('0'); }); - expect(inputElm.val()).toBe('0'); - }); - - describe('pattern', function() { + describe('pattern', function () { - it('should validate in-lined pattern', function() { - compileInput(''); - scope.$digest(); + it('should validate in-lined pattern', function () { + compileInput(''); + scope.$digest(); - changeInputValueTo('x000-00-0000x'); - expect(inputElm).toBeInvalid(); + changeInputValueTo('x000-00-0000x'); + expect(inputElm).toBeInvalid(); - changeInputValueTo('000-00-0000'); - expect(inputElm).toBeValid(); + changeInputValueTo('000-00-0000'); + expect(inputElm).toBeValid(); - changeInputValueTo('000-00-0000x'); - expect(inputElm).toBeInvalid(); + changeInputValueTo('000-00-0000x'); + expect(inputElm).toBeInvalid(); - changeInputValueTo('123-45-6789'); - expect(inputElm).toBeValid(); + changeInputValueTo('123-45-6789'); + expect(inputElm).toBeValid(); - changeInputValueTo('x'); - expect(inputElm).toBeInvalid(); - }); + changeInputValueTo('x'); + expect(inputElm).toBeInvalid(); + }); - it('should validate in-lined pattern with modifiers', function() { - compileInput(''); - scope.$digest(); + it('should validate in-lined pattern with modifiers', function () { + compileInput(''); + scope.$digest(); - changeInputValueTo('aB'); - expect(inputElm).toBeValid(); + changeInputValueTo('aB'); + expect(inputElm).toBeValid(); - changeInputValueTo('xx'); - expect(inputElm).toBeInvalid(); - }); + changeInputValueTo('xx'); + expect(inputElm).toBeInvalid(); + }); - it('should validate pattern from scope', function() { - compileInput(''); - scope.regexp = /^\d\d\d-\d\d-\d\d\d\d$/; - scope.$digest(); + it('should validate pattern from scope', function () { + compileInput(''); + scope.regexp = /^\d\d\d-\d\d-\d\d\d\d$/; + scope.$digest(); - changeInputValueTo('x000-00-0000x'); - expect(inputElm).toBeInvalid(); + changeInputValueTo('x000-00-0000x'); + expect(inputElm).toBeInvalid(); - changeInputValueTo('000-00-0000'); - expect(inputElm).toBeValid(); + changeInputValueTo('000-00-0000'); + expect(inputElm).toBeValid(); - changeInputValueTo('000-00-0000x'); - expect(inputElm).toBeInvalid(); + changeInputValueTo('000-00-0000x'); + expect(inputElm).toBeInvalid(); - changeInputValueTo('123-45-6789'); - expect(inputElm).toBeValid(); + changeInputValueTo('123-45-6789'); + expect(inputElm).toBeValid(); - changeInputValueTo('x'); - expect(inputElm).toBeInvalid(); + changeInputValueTo('x'); + expect(inputElm).toBeInvalid(); - scope.regexp = /abc?/; + scope.regexp = /abc?/; - changeInputValueTo('ab'); - expect(inputElm).toBeValid(); + changeInputValueTo('ab'); + expect(inputElm).toBeValid(); - changeInputValueTo('xx'); - expect(inputElm).toBeInvalid(); - }); + changeInputValueTo('xx'); + expect(inputElm).toBeInvalid(); + }); - it('should throw an error when scope pattern can\'t be found', function() { - expect(function() { - compileInput(''); - scope.$apply(); - }).toThrowMatching(/^\[ngPattern:noregexp\] Expected fooRegexp to be a RegExp but was/); + it('should throw an error when scope pattern can\'t be found', function () { + expect(function () { + compileInput(''); + scope.$apply(); + }).toThrowMatching(/^\[ngPattern:noregexp\] Expected fooRegexp to be a RegExp but was/); + }); }); - }); - describe('minlength', function() { + describe('minlength', function () { - it('should invalid shorter than given minlength', function() { - compileInput(''); + it('should invalid shorter than given minlength', function () { + compileInput(''); - changeInputValueTo('aa'); - expect(scope.value).toBeUndefined(); + changeInputValueTo('aa'); + expect(scope.value).toBeUndefined(); - changeInputValueTo('aaa'); - expect(scope.value).toBe('aaa'); + changeInputValueTo('aaa'); + expect(scope.value).toBe('aaa'); + }); }); - }); - describe('maxlength', function() { + describe('maxlength', function () { - it('should invalid shorter than given maxlength', function() { - compileInput(''); + it('should invalid shorter than given maxlength', function () { + compileInput(''); - changeInputValueTo('aaaaaaaa'); - expect(scope.value).toBeUndefined(); + changeInputValueTo('aaaaaaaa'); + expect(scope.value).toBeUndefined(); - changeInputValueTo('aaa'); - expect(scope.value).toBe('aaa'); + changeInputValueTo('aaa'); + expect(scope.value).toBe('aaa'); + }); }); - }); - // INPUT TYPES + // INPUT TYPES - describe('number', function() { + describe('number', function () { - it('should reset the model if view is invalid', function() { - compileInput(''); + it('should reset the model if view is invalid', function () { + compileInput(''); - scope.$apply(function() { - scope.age = 123; - }); - expect(inputElm.val()).toBe('123'); - - try { - // to allow non-number values, we have to change type so that - // the browser which have number validation will not interfere with - // this test. IE8 won't allow it hence the catch. - inputElm[0].setAttribute('type', 'text'); - } catch (e) {} - - changeInputValueTo('123X'); - expect(inputElm.val()).toBe('123X'); - expect(scope.age).toBeUndefined(); - expect(inputElm).toBeInvalid(); - }); + scope.$apply(function () { + scope.age = 123; + }); + expect(inputElm.val()).toBe('123'); + try { + // to allow non-number values, we have to change type so that + // the browser which have number validation will not interfere with + // this test. IE8 won't allow it hence the catch. + inputElm[0].setAttribute('type', 'text'); + } catch (e) { } - it('should render as blank if null', function() { - compileInput(''); + changeInputValueTo('123X'); + expect(inputElm.val()).toBe('123X'); + expect(scope.age).toBeUndefined(); + expect(inputElm).toBeInvalid(); + }); - scope.$apply(function() { - scope.age = null; - }); - expect(scope.age).toBeNull(); - expect(inputElm.val()).toEqual(''); - }); + it('should render as blank if null', function () { + compileInput(''); + scope.$apply(function () { + scope.age = null; + }); - it('should come up blank when no value specified', function() { - compileInput(''); + expect(scope.age).toBeNull(); + expect(inputElm.val()).toEqual(''); + }); - scope.$digest(); - expect(inputElm.val()).toBe(''); - scope.$apply(function() { - scope.age = null; - }); + it('should come up blank when no value specified', function () { + compileInput(''); - expect(scope.age).toBeNull(); - expect(inputElm.val()).toBe(''); - }); + scope.$digest(); + expect(inputElm.val()).toBe(''); + scope.$apply(function () { + scope.age = null; + }); - it('should parse empty string to null', function() { - compileInput(''); + expect(scope.age).toBeNull(); + expect(inputElm.val()).toBe(''); + }); - scope.$apply(function() { - scope.age = 10; - }); - changeInputValueTo(''); - expect(scope.age).toBeNull(); - expect(inputElm).toBeValid(); - }); + it('should parse empty string to null', function () { + compileInput(''); - it('should parse "." to zero', function () { - compileInput(''); - changeInputValueTo('.'); - expect(scope.price).toBe(0); - expect(inputElm).toBeValid(); - expect(inputElm.val()).toBe('.'); - }); + scope.$apply(function () { + scope.age = 10; + }); + + changeInputValueTo(''); + expect(scope.age).toBeNull(); + expect(inputElm).toBeValid(); + }); + + it('should parse "." to zero', function () { + compileInput(''); + changeInputValueTo('.'); + expect(scope.price).toBe(0); + expect(inputElm).toBeValid(); + expect(inputElm.val()).toBe('.'); + }); - describe('min', function() { + describe('min', function () { - it('should validate', function() { - compileInput(''); - scope.$digest(); + it('should validate', function () { + compileInput(''); + scope.$digest(); - changeInputValueTo('1'); - expect(inputElm).toBeInvalid(); - expect(scope.value).toBeFalsy(); - expect(scope.form.alias.$error.min).toBeTruthy(); + changeInputValueTo('1'); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeFalsy(); + expect(scope.form.alias.$error.min).toBeTruthy(); - changeInputValueTo('100'); - expect(inputElm).toBeValid(); - expect(scope.value).toBe(100); - expect(scope.form.alias.$error.min).toBeFalsy(); - }); + changeInputValueTo('100'); + expect(inputElm).toBeValid(); + expect(scope.value).toBe(100); + expect(scope.form.alias.$error.min).toBeFalsy(); + }); - it('should validate even if min value changes on-the-fly', function(done) { - scope.min = 10; - compileInput(''); - scope.$digest(); + it('should validate even if min value changes on-the-fly', function (done) { + scope.min = 10; + compileInput(''); + scope.$digest(); - changeInputValueTo('5'); - expect(inputElm).toBeInvalid(); + changeInputValueTo('5'); + expect(inputElm).toBeInvalid(); - scope.min = 0; - scope.$digest(function () { - expect(inputElm).toBeValid(); - done(); + scope.min = 0; + scope.$digest(function () { + expect(inputElm).toBeValid(); + done(); + }); + }); }); - }); - }); - describe('max', function() { + describe('max', function () { - it('should validate', function() { - compileInput(''); - scope.$digest(); + it('should validate', function () { + compileInput(''); + scope.$digest(); - changeInputValueTo('20'); - expect(inputElm).toBeInvalid(); - expect(scope.value).toBeFalsy(); - expect(scope.form.alias.$error.max).toBeTruthy(); + changeInputValueTo('20'); + expect(inputElm).toBeInvalid(); + expect(scope.value).toBeFalsy(); + expect(scope.form.alias.$error.max).toBeTruthy(); - changeInputValueTo('0'); - expect(inputElm).toBeValid(); - expect(scope.value).toBe(0); - expect(scope.form.alias.$error.max).toBeFalsy(); - }); + changeInputValueTo('0'); + expect(inputElm).toBeValid(); + expect(scope.value).toBe(0); + expect(scope.form.alias.$error.max).toBeFalsy(); + }); - it('should validate even if max value changes on-the-fly', function(done) { - scope.max = 10; - compileInput(''); - scope.$digest(); + it('should validate even if max value changes on-the-fly', function (done) { + scope.max = 10; + compileInput(''); + scope.$digest(); - changeInputValueTo('5'); - expect(inputElm).toBeValid(); + changeInputValueTo('5'); + expect(inputElm).toBeValid(); - scope.max = 0; - scope.$digest(function () { - expect(inputElm).toBeInvalid(); - done(); + scope.max = 0; + scope.$digest(function () { + expect(inputElm).toBeInvalid(); + done(); + }); + }); }); - }); - }); - describe('required', function() { + describe('required', function () { - it('should be valid even if value is 0', function() { - compileInput(''); + it('should be valid even if value is 0', function () { + compileInput(''); - changeInputValueTo('0'); - expect(inputElm).toBeValid(); - expect(scope.value).toBe(0); - expect(scope.form.alias.$error.required).toBeFalsy(); - }); + changeInputValueTo('0'); + expect(inputElm).toBeValid(); + expect(scope.value).toBe(0); + expect(scope.form.alias.$error.required).toBeFalsy(); + }); - it('should be valid even if value 0 is set from model', function() { - compileInput(''); + it('should be valid even if value 0 is set from model', function () { + compileInput(''); - scope.$apply(function() { - scope.value = 0; - }); + scope.$apply(function () { + scope.value = 0; + }); - expect(inputElm).toBeValid(); - expect(inputElm.val()).toBe('0') - expect(scope.form.alias.$error.required).toBeFalsy(); - }); + expect(inputElm).toBeValid(); + expect(inputElm.val()).toBe('0') + expect(scope.form.alias.$error.required).toBeFalsy(); + }); - it('should register required on non boolean elements', function() { - compileInput('
'); + it('should register required on non boolean elements', function () { + compileInput('
'); - scope.$apply(function() { - scope.value = ''; - }); + scope.$apply(function () { + scope.value = ''; + }); - expect(inputElm).toBeInvalid(); - expect(scope.form.alias.$error.required).toBeTruthy(); - }); + expect(inputElm).toBeInvalid(); + expect(scope.form.alias.$error.required).toBeTruthy(); + }); + }); }); - }); - describe('email', function() { + describe('email', function () { - it('should validate e-mail', function() { - compileInput(''); + it('should validate e-mail', function () { + compileInput(''); - var widget = scope.form.alias; - changeInputValueTo('vojta@google.com'); + var widget = scope.form.alias; + changeInputValueTo('vojta@google.com'); - expect(scope.email).toBe('vojta@google.com'); - expect(inputElm).toBeValid(); - expect(widget.$error.email).toBe(false); + expect(scope.email).toBe('vojta@google.com'); + expect(inputElm).toBeValid(); + expect(widget.$error.email).toBe(false); - changeInputValueTo('invalid@'); - expect(scope.email).toBeUndefined(); - expect(inputElm).toBeInvalid(); - expect(widget.$error.email).toBeTruthy(); - }); + changeInputValueTo('invalid@'); + expect(scope.email).toBeUndefined(); + expect(inputElm).toBeInvalid(); + expect(widget.$error.email).toBeTruthy(); + }); - describe('EMAIL_REGEXP', function() { + describe('EMAIL_REGEXP', function () { - it('should validate email', function() { - expect(EMAIL_REGEXP.test('a@b.com')).toBe(true); - expect(EMAIL_REGEXP.test('a@b.museum')).toBe(true); - expect(EMAIL_REGEXP.test('a@B.c')).toBe(false); - }); + it('should validate email', function () { + expect(EMAIL_REGEXP.test('a@b.com')).toBe(true); + expect(EMAIL_REGEXP.test('a@b.museum')).toBe(true); + expect(EMAIL_REGEXP.test('a@B.c')).toBe(false); + }); + }); }); - }); - describe('url', function() { + describe('url', function () { - it('should validate url', function() { - compileInput(''); - var widget = scope.form.alias; + it('should validate url', function () { + compileInput(''); + var widget = scope.form.alias; - changeInputValueTo('http://www.something.com'); - expect(scope.url).toBe('http://www.something.com'); - expect(inputElm).toBeValid(); - expect(widget.$error.url).toBe(false); + changeInputValueTo('http://www.something.com'); + expect(scope.url).toBe('http://www.something.com'); + expect(inputElm).toBeValid(); + expect(widget.$error.url).toBe(false); - changeInputValueTo('invalid.com'); - expect(scope.url).toBeUndefined(); - expect(inputElm).toBeInvalid(); - expect(widget.$error.url).toBeTruthy(); - }); + changeInputValueTo('invalid.com'); + expect(scope.url).toBeUndefined(); + expect(inputElm).toBeInvalid(); + expect(widget.$error.url).toBeTruthy(); + }); - describe('URL_REGEXP', function() { + describe('URL_REGEXP', function () { - it('should validate url', function() { - expect(URL_REGEXP.test('http://server:123/path')).toBe(true); - expect(URL_REGEXP.test('a@B.c')).toBe(false); - }); + it('should validate url', function () { + expect(URL_REGEXP.test('http://server:123/path')).toBe(true); + expect(URL_REGEXP.test('a@B.c')).toBe(false); + }); + }); }); - }); - describe('radio', function() { + describe('radio', function () { - it('should update the model', function() { - compileInput( + it('should update the model', function () { + compileInput( '' + '' + ''); - scope.$apply(function() { - scope.color = 'white'; - }); - expect(inputElm[0].checked).toBe(true); - expect(inputElm[1].checked).toBe(false); - expect(inputElm[2].checked).toBe(false); - - scope.$apply(function() { - scope.color = 'red'; - }); - expect(inputElm[0].checked).toBe(false); - expect(inputElm[1].checked).toBe(true); - expect(inputElm[2].checked).toBe(false); - - browserTrigger(inputElm[2], 'click'); - expect(scope.color).toBe('blue'); - }); + scope.$apply(function () { + scope.color = 'white'; + }); + expect(inputElm[0].checked).toBe(true); + expect(inputElm[1].checked).toBe(false); + expect(inputElm[2].checked).toBe(false); + + scope.$apply(function () { + scope.color = 'red'; + }); + expect(inputElm[0].checked).toBe(false); + expect(inputElm[1].checked).toBe(true); + expect(inputElm[2].checked).toBe(false); + + browserTrigger(inputElm[2], 'click'); + expect(scope.color).toBe('blue'); + }); - it('should allow {{expr}} as value', function() { - scope.some = 11; - compileInput( + it('should allow {{expr}} as value', function () { + scope.some = 11; + compileInput( '' + ''); - scope.$apply(function() { - scope.value = 'blue'; - scope.some = 'blue'; - scope.other = 'red'; - }); + scope.$apply(function () { + scope.value = 'blue'; + scope.some = 'blue'; + scope.other = 'red'; + }); - expect(inputElm[0].checked).toBe(true); - expect(inputElm[1].checked).toBe(false); + expect(inputElm[0].checked).toBe(true); + expect(inputElm[1].checked).toBe(false); - browserTrigger(inputElm[1], 'click'); - expect(scope.value).toBe('red'); + browserTrigger(inputElm[1], 'click'); + expect(scope.value).toBe('red'); - scope.$apply(function() { - scope.other = 'non-red'; - }); + scope.$apply(function () { + scope.other = 'non-red'; + }); - expect(inputElm[0].checked).toBe(false); - expect(inputElm[1].checked).toBe(false); + expect(inputElm[0].checked).toBe(false); + expect(inputElm[1].checked).toBe(false); + }); }); - }); - describe('checkbox', function() { + describe('checkbox', function () { - it('should ignore checkbox without ngModel directive', function() { - compileInput(''); + it('should ignore checkbox without ngModel directive', function () { + compileInput(''); - changeInputValueTo(''); - expect(inputElm.hasClass('ng-valid')).toBe(false); - expect(inputElm.hasClass('ng-invalid')).toBe(false); - expect(inputElm.hasClass('ng-pristine')).toBe(false); - expect(inputElm.hasClass('ng-dirty')).toBe(false); - }); + changeInputValueTo(''); + expect(inputElm.hasClass('ng-valid')).toBe(false); + expect(inputElm.hasClass('ng-invalid')).toBe(false); + expect(inputElm.hasClass('ng-pristine')).toBe(false); + expect(inputElm.hasClass('ng-dirty')).toBe(false); + }); - it('should format booleans', function() { - compileInput(''); + it('should format booleans', function () { + compileInput(''); - scope.$apply(function() { - scope.name = false; - }); - expect(inputElm[0].checked).toBe(false); + scope.$apply(function () { + scope.name = false; + }); + expect(inputElm[0].checked).toBe(false); - scope.$apply(function() { - scope.name = true; - }); - expect(inputElm[0].checked).toBe(true); - }); + scope.$apply(function () { + scope.name = true; + }); + expect(inputElm[0].checked).toBe(true); + }); - it('should support type="checkbox" with non-standard capitalization', function() { - compileInput(''); + it('should support type="checkbox" with non-standard capitalization', function () { + compileInput(''); - browserTrigger(inputElm, 'click'); - expect(scope.checkbox).toBe(true); + browserTrigger(inputElm, 'click'); + expect(scope.checkbox).toBe(true); - browserTrigger(inputElm, 'click'); - expect(scope.checkbox).toBe(false); - }); + browserTrigger(inputElm, 'click'); + expect(scope.checkbox).toBe(false); + }); - it('should allow custom enumeration', function() { - compileInput(''); - scope.$apply(function() { - scope.name = 'y'; - }); - expect(inputElm[0].checked).toBe(true); + scope.$apply(function () { + scope.name = 'y'; + }); + expect(inputElm[0].checked).toBe(true); - scope.$apply(function() { - scope.name = 'n'; - }); - expect(inputElm[0].checked).toBe(false); + scope.$apply(function () { + scope.name = 'n'; + }); + expect(inputElm[0].checked).toBe(false); - scope.$apply(function() { - scope.name = 'something else'; - }); - expect(inputElm[0].checked).toBe(false); + scope.$apply(function () { + scope.name = 'something else'; + }); + expect(inputElm[0].checked).toBe(false); - browserTrigger(inputElm, 'click'); - expect(scope.name).toEqual('y'); + browserTrigger(inputElm, 'click'); + expect(scope.name).toEqual('y'); - browserTrigger(inputElm, 'click'); - expect(scope.name).toEqual('n'); - }); + browserTrigger(inputElm, 'click'); + expect(scope.name).toEqual('n'); + }); - it('should be required if false', function() { - compileInput(''); + 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(true); + expect(inputElm).toBeValid(); - browserTrigger(inputElm, 'click'); - expect(inputElm[0].checked).toBe(false); - expect(inputElm).toBeInvalid(); + browserTrigger(inputElm, 'click'); + expect(inputElm[0].checked).toBe(false); + expect(inputElm).toBeInvalid(); + }); }); - }); - describe('textarea', function() { + describe('textarea', function () { - it("should process textarea", function() { - compileInput(''); - inputElm = formElm.find('textarea'); + it("should process textarea", function () { + compileInput(''); + inputElm = formElm.find('textarea'); - scope.$apply(function() { - scope.name = 'Adam'; - }); - expect(inputElm.val()).toEqual('Adam'); + scope.$apply(function () { + scope.name = 'Adam'; + }); + expect(inputElm.val()).toEqual('Adam'); - changeInputValueTo('Shyam'); - expect(scope.name).toEqual('Shyam'); + changeInputValueTo('Shyam'); + expect(scope.name).toEqual('Shyam'); - changeInputValueTo('Kai'); - expect(scope.name).toEqual('Kai'); - }); + changeInputValueTo('Kai'); + expect(scope.name).toEqual('Kai'); + }); - it('should ignore textarea without ngModel directive', function() { - compileInput(''); - inputElm = formElm.find('textarea'); + it('should ignore textarea without ngModel directive', function () { + compileInput(''); + inputElm = formElm.find('textarea'); - changeInputValueTo(''); - expect(inputElm.hasClass('ng-valid')).toBe(false); - expect(inputElm.hasClass('ng-invalid')).toBe(false); - expect(inputElm.hasClass('ng-pristine')).toBe(false); - expect(inputElm.hasClass('ng-dirty')).toBe(false); + changeInputValueTo(''); + expect(inputElm.hasClass('ng-valid')).toBe(false); + expect(inputElm.hasClass('ng-invalid')).toBe(false); + expect(inputElm.hasClass('ng-pristine')).toBe(false); + expect(inputElm.hasClass('ng-dirty')).toBe(false); + }); }); - }); - describe('ngList', function() { + describe('ngList', function () { - it('should parse text into an array', function() { - compileInput(''); + it('should parse text into an array', function () { + compileInput(''); - // model -> view - scope.$apply(function() { - scope.list = ['x', 'y', 'z']; - }); - expect(inputElm.val()).toBe('x, y, z'); + // model -> view + scope.$apply(function () { + scope.list = ['x', 'y', 'z']; + }); + expect(inputElm.val()).toBe('x, y, z'); - // view -> model - changeInputValueTo('1, 2, 3'); - expect(scope.list).toEqual(['1', '2', '3']); - }); + // view -> model + changeInputValueTo('1, 2, 3'); + expect(scope.list).toEqual(['1', '2', '3']); + }); - it("should not clobber text if model changes due to itself", function() { - // When the user types 'a,b' the 'a,' stage parses to ['a'] but if the - // $parseModel function runs it will change to 'a', in essence preventing - // the user from ever typying ','. - compileInput(''); + it("should not clobber text if model changes due to itself", function () { + // When the user types 'a,b' the 'a,' stage parses to ['a'] but if the + // $parseModel function runs it will change to 'a', in essence preventing + // the user from ever typying ','. + compileInput(''); - changeInputValueTo('a '); - expect(inputElm.val()).toEqual('a '); - expect(scope.list).toEqual(['a']); + changeInputValueTo('a '); + expect(inputElm.val()).toEqual('a '); + expect(scope.list).toEqual(['a']); - changeInputValueTo('a ,'); - expect(inputElm.val()).toEqual('a ,'); - expect(scope.list).toEqual(['a']); + changeInputValueTo('a ,'); + expect(inputElm.val()).toEqual('a ,'); + expect(scope.list).toEqual(['a']); - changeInputValueTo('a , '); - expect(inputElm.val()).toEqual('a , '); - expect(scope.list).toEqual(['a']); + changeInputValueTo('a , '); + expect(inputElm.val()).toEqual('a , '); + expect(scope.list).toEqual(['a']); - changeInputValueTo('a , b'); - expect(inputElm.val()).toEqual('a , b'); - expect(scope.list).toEqual(['a', 'b']); - }); + changeInputValueTo('a , b'); + expect(inputElm.val()).toEqual('a , b'); + expect(scope.list).toEqual(['a', 'b']); + }); - it('should convert empty string to an empty array', function() { - compileInput(''); + it('should convert empty string to an empty array', function () { + compileInput(''); - changeInputValueTo(''); - expect(scope.list).toEqual([]); - }); + changeInputValueTo(''); + expect(scope.list).toEqual([]); + }); - it('should be invalid if required and empty', function() { - compileInput(''); - changeInputValueTo(''); - expect(scope.list).toBeUndefined(); - expect(inputElm).toBeInvalid(); - changeInputValueTo('a,b'); - expect(scope.list).toEqual(['a','b']); - expect(inputElm).toBeValid(); - }); + it('should be invalid if required and empty', function () { + compileInput(''); + changeInputValueTo(''); + expect(scope.list).toBeUndefined(); + expect(inputElm).toBeInvalid(); + changeInputValueTo('a,b'); + expect(scope.list).toEqual(['a', 'b']); + expect(inputElm).toBeValid(); + }); - it('should allow custom separator', function() { - compileInput(''); + it('should allow custom separator', function () { + compileInput(''); - changeInputValueTo('a,a'); - expect(scope.list).toEqual(['a,a']); + changeInputValueTo('a,a'); + expect(scope.list).toEqual(['a,a']); - changeInputValueTo('a:b'); - expect(scope.list).toEqual(['a', 'b']); - }); + changeInputValueTo('a:b'); + expect(scope.list).toEqual(['a', 'b']); + }); - it('should allow regexp as a separator', function() { - compileInput(''); + it('should allow regexp as a separator', function () { + compileInput(''); - changeInputValueTo('a,b'); - expect(scope.list).toEqual(['a', 'b']); + changeInputValueTo('a,b'); + expect(scope.list).toEqual(['a', 'b']); - changeInputValueTo('a,b: c'); - expect(scope.list).toEqual(['a', 'b', 'c']); + changeInputValueTo('a,b: c'); + expect(scope.list).toEqual(['a', 'b', 'c']); + }); }); - }); - describe('required', function() { + describe('required', function () { - it('should allow bindings via ngRequired', function() { - compileInput(''); + it('should allow bindings via ngRequired', function () { + compileInput(''); - scope.$apply(function() { - scope.required = false; - }); + scope.$apply(function () { + scope.required = false; + }); - changeInputValueTo(''); - expect(inputElm).toBeValid(); + changeInputValueTo(''); + expect(inputElm).toBeValid(); - scope.$apply(function() { - scope.required = true; - }); - expect(inputElm).toBeInvalid(); + scope.$apply(function () { + scope.required = true; + }); + expect(inputElm).toBeInvalid(); - scope.$apply(function() { - scope.value = 'some'; - }); - expect(inputElm).toBeValid(); + scope.$apply(function () { + scope.value = 'some'; + }); + expect(inputElm).toBeValid(); - changeInputValueTo(''); - expect(inputElm).toBeInvalid(); + changeInputValueTo(''); + expect(inputElm).toBeInvalid(); - scope.$apply(function() { - scope.required = false; - }); - expect(inputElm).toBeValid(); - }); + scope.$apply(function () { + scope.required = false; + }); + expect(inputElm).toBeValid(); + }); - it('should invalid initial value with bound required', function() { - compileInput(''); + it('should invalid initial value with bound required', function () { + compileInput(''); - scope.$apply(function() { - scope.required = true; - }); + scope.$apply(function () { + scope.required = true; + }); - expect(inputElm).toBeInvalid(); - }); + expect(inputElm).toBeInvalid(); + }); - it('should be $invalid but $pristine if not touched', function() { - compileInput(''); + it('should be $invalid but $pristine if not touched', function () { + compileInput(''); - scope.$apply(function() { - scope.name = ''; - }); + scope.$apply(function () { + scope.name = ''; + }); - expect(inputElm).toBeInvalid(); - expect(inputElm).toBePristine(); + expect(inputElm).toBeInvalid(); + expect(inputElm).toBePristine(); - changeInputValueTo(''); - expect(inputElm).toBeInvalid(); - expect(inputElm).toBeDirty(); - }); + changeInputValueTo(''); + expect(inputElm).toBeInvalid(); + expect(inputElm).toBeDirty(); + }); - it('should allow empty string if not required', function() { - compileInput(''); - changeInputValueTo('a'); - changeInputValueTo(''); - expect(scope.foo).toBe(''); - }); + it('should allow empty string if not required', function () { + compileInput(''); + changeInputValueTo('a'); + changeInputValueTo(''); + expect(scope.foo).toBe(''); + }); - it('should set $invalid when model undefined', function() { - compileInput(''); - scope.$digest(); - expect(inputElm).toBeInvalid(); - }); + it('should set $invalid when model undefined', function () { + compileInput(''); + scope.$digest(); + expect(inputElm).toBeInvalid(); + }); - it('should allow `false` as a valid value when the input type is not "checkbox"', function() { - compileInput('' + + it('should allow `false` as a valid value when the input type is not "checkbox"', function () { + compileInput('' + ''); - scope.$apply(); - expect(inputElm).toBeInvalid(); + scope.$apply(); + expect(inputElm).toBeInvalid(); - scope.$apply(function() { - scope.answer = true; - }); - expect(inputElm).toBeValid(); + scope.$apply(function () { + scope.answer = true; + }); + expect(inputElm).toBeValid(); - scope.$apply(function() { - scope.answer = false; - }); - expect(inputElm).toBeValid(); + scope.$apply(function () { + scope.answer = false; + }); + expect(inputElm).toBeValid(); + }); }); - }); - describe('ngChange', function() { + describe('ngChange', function () { - it('should $eval expression after new value is set in the model', function() { - compileInput(''); + it('should $eval expression after new value is set in the model', function () { + compileInput(''); - scope.change = jasmine.createSpy('change').andCallFake(function() { - expect(scope.value).toBe('new value'); - }); + scope.change = jasmine.createSpy('change').andCallFake(function () { + expect(scope.value).toBe('new value'); + }); - changeInputValueTo('new value'); - expect(scope.change).toHaveBeenCalledOnce(); - }); + changeInputValueTo('new value'); + expect(scope.change).toHaveBeenCalledOnce(); + }); - it('should not $eval the expression if changed from model', function() { - compileInput(''); + it('should not $eval the expression if changed from model', function () { + compileInput(''); - scope.change = jasmine.createSpy('change'); - scope.$apply(function() { - scope.value = true; - }); + scope.change = jasmine.createSpy('change'); + scope.$apply(function () { + scope.value = true; + }); - expect(scope.change).not.toHaveBeenCalled(); - }); + expect(scope.change).not.toHaveBeenCalled(); + }); - it('should $eval ngChange expression on checkbox', function() { - compileInput(''); + it('should $eval ngChange expression on checkbox', function () { + compileInput(''); - scope.changeFn = jasmine.createSpy('changeFn'); - scope.$digest(); - expect(scope.changeFn).not.toHaveBeenCalled(); + scope.changeFn = jasmine.createSpy('changeFn'); + scope.$digest(); + expect(scope.changeFn).not.toHaveBeenCalled(); - browserTrigger(inputElm, 'click'); - expect(scope.changeFn).toHaveBeenCalledOnce(); + browserTrigger(inputElm, 'click'); + expect(scope.changeFn).toHaveBeenCalledOnce(); + }); }); - }); - describe('ngValue', function() { + describe('ngValue', function () { - it('should update the dom "value" property and attribute', function() { - compileInput(''); + it('should update the dom "value" property and attribute', function () { + compileInput(''); - scope.$apply(function() { - scope.value = 'something'; - }); + scope.$apply(function () { + scope.value = 'something'; + }); - expect(inputElm[0].value).toBe('something'); - expect(inputElm[0].getAttribute('value')).toBe('something'); - }); + expect(inputElm[0].value).toBe('something'); + expect(inputElm[0].getAttribute('value')).toBe('something'); + }); - it('should evaluate and set constant expressions', function() { - compileInput('' + + it('should evaluate and set constant expressions', function () { + compileInput('' + '' + ''); - scope.$digest(); + scope.$digest(); - browserTrigger(inputElm[0], 'click'); - expect(scope.selected).toBe(true); + browserTrigger(inputElm[0], 'click'); + expect(scope.selected).toBe(true); - browserTrigger(inputElm[1], 'click'); - expect(scope.selected).toBe(false); + browserTrigger(inputElm[1], 'click'); + expect(scope.selected).toBe(false); - browserTrigger(inputElm[2], 'click'); - expect(scope.selected).toBe(1); - }); + browserTrigger(inputElm[2], 'click'); + expect(scope.selected).toBe(1); + }); - it('should watch the expression', function() { - compileInput(''); + it('should watch the expression', function () { + compileInput(''); - scope.$apply(function() { - scope.selected = scope.value = {some: 'object'}; - }); - expect(inputElm[0].checked).toBe(true); + scope.$apply(function () { + scope.selected = scope.value = { some: 'object' }; + }); + expect(inputElm[0].checked).toBe(true); - scope.$apply(function() { - scope.value = {some: 'other'}; - }); - expect(inputElm[0].checked).toBe(false); + scope.$apply(function () { + scope.value = { some: 'other' }; + }); + expect(inputElm[0].checked).toBe(false); - browserTrigger(inputElm, 'click'); - expect(scope.selected).toBe(scope.value); - }); + browserTrigger(inputElm, 'click'); + expect(scope.selected).toBe(scope.value); + }); - it('should work inside ngRepeat', function() { - compileInput( + it('should work inside ngRepeat', function () { + compileInput( ''); - scope.$apply(function() { - scope.items = [{id: 1}, {id: 2}]; - scope.selected = 1; - }); + scope.$apply(function () { + scope.items = [{ id: 1 }, { id: 2}]; + scope.selected = 1; + }); - inputElm = formElm.find('input'); - expect(inputElm[0].checked).toBe(true); - expect(inputElm[1].checked).toBe(false); + inputElm = formElm.find('input'); + expect(inputElm[0].checked).toBe(true); + expect(inputElm[1].checked).toBe(false); - browserTrigger(inputElm.eq(1), 'click'); - expect(scope.selected).toBe(2); - }); + browserTrigger(inputElm.eq(1), 'click'); + expect(scope.selected).toBe(2); + }); - it('should work inside ngRepeat with primitive values', function() { - compileInput( + it('should work inside ngRepeat with primitive values', function () { + compileInput( '
' + '' + '' + '
'); - scope.$apply(function() { - scope.items = [{id: 1, selected: true}, {id: 2, selected: false}]; - }); + scope.$apply(function () { + scope.items = [{ id: 1, selected: true }, { id: 2, selected: false}]; + }); - inputElm = formElm.find('input'); - expect(inputElm[0].checked).toBe(true); - expect(inputElm[1].checked).toBe(false); - expect(inputElm[2].checked).toBe(false); - expect(inputElm[3].checked).toBe(true); + inputElm = formElm.find('input'); + expect(inputElm[0].checked).toBe(true); + expect(inputElm[1].checked).toBe(false); + expect(inputElm[2].checked).toBe(false); + expect(inputElm[3].checked).toBe(true); - browserTrigger(inputElm.eq(1), 'click'); - expect(scope.items[0].selected).toBe(false); - }); + browserTrigger(inputElm.eq(1), 'click'); + expect(scope.items[0].selected).toBe(false); + }); - it('should work inside ngRepeat without name attribute', function() { - compileInput( + it('should work inside ngRepeat without name attribute', function () { + compileInput( '
' + '' + '' + '
'); - scope.$apply(function() { - scope.items = [{id: 1, selected: true}, {id: 2, selected: false}]; - }); + scope.$apply(function () { + scope.items = [{ id: 1, selected: true }, { id: 2, selected: false}]; + }); - inputElm = formElm.find('input'); - expect(inputElm[0].checked).toBe(true); - expect(inputElm[1].checked).toBe(false); - expect(inputElm[2].checked).toBe(false); - expect(inputElm[3].checked).toBe(true); + inputElm = formElm.find('input'); + expect(inputElm[0].checked).toBe(true); + expect(inputElm[1].checked).toBe(false); + expect(inputElm[2].checked).toBe(false); + expect(inputElm[3].checked).toBe(true); - browserTrigger(inputElm.eq(1), 'click'); - expect(scope.items[0].selected).toBe(false); + browserTrigger(inputElm.eq(1), 'click'); + expect(scope.items[0].selected).toBe(false); + }); }); - }); }); From a459ec40c1da0d1bd59a0f28f868434db3c3bc60 Mon Sep 17 00:00:00 2001 From: Joe Enzminger Date: Thu, 9 Jan 2014 10:10:14 -0600 Subject: [PATCH 4/4] removed checks for element validity and value --- test/ng/directive/inputSpec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 876941c66812..e0dce7d036ae 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -815,11 +815,9 @@ describe('input', function () { expect(inputElm).toBeValid(); }); - it('should parse "." to zero', function () { + it('should allow "." in input element', function () { compileInput(''); changeInputValueTo('.'); - expect(scope.price).toBe(0); - expect(inputElm).toBeValid(); expect(inputElm.val()).toBe('.'); });