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

Commit 0ef1727

Browse files
shahatapetebacondarwin
authored andcommittedMay 9, 2014
refactor(inputSpec): move call to $digest into compileInput helper
It is reasonable to expect a digest to occur between an input element compiling and the first user interaction. Rather than add digests to each test this change moves it into the `compileInput` helper function.
1 parent ac37915 commit 0ef1727

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed
 

‎test/ng/directive/inputSpec.js

+2-36
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ describe('input', function() {
420420
formElm = jqLite('<form name="form"></form>');
421421
formElm.append(inputElm);
422422
$compile(formElm)(scope);
423+
scope.$digest();
423424
}
424425

425426
beforeEach(inject(function($injector, _$sniffer_, _$browser_) {
@@ -915,7 +916,6 @@ describe('input', function() {
915916
compileInput(
916917
'<input type="text" ng-model="name" name="alias" '+
917918
'ng-model-options="{ updateOn: \'blur\' }" />');
918-
scope.$digest();
919919

920920
changeInputValueTo('a');
921921
expect(inputElm.val()).toBe('a');
@@ -929,7 +929,6 @@ describe('input', function() {
929929
compileInput(
930930
'<input type="text" ng-model="name" name="alias" '+
931931
'ng-model-options="{ debounce: 2000 }" />');
932-
scope.$digest();
933932

934933
changeInputValueTo('a');
935934
expect(inputElm.val()).toBe('a');
@@ -965,7 +964,6 @@ describe('input', function() {
965964
it('should report error on assignment error', function() {
966965
expect(function() {
967966
compileInput('<input type="text" ng-model="throw \'\'">');
968-
scope.$digest();
969967
}).toThrowMinErr("$parse", "syntax", "Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw ''] starting at [''].");
970968
});
971969

@@ -996,7 +994,6 @@ describe('input', function() {
996994

997995
it('should validate in-lined pattern', function() {
998996
compileInput('<input type="text" ng-model="value" ng-pattern="/^\\d\\d\\d-\\d\\d-\\d\\d\\d\\d$/" />');
999-
scope.$digest();
1000997

1001998
changeInputValueTo('x000-00-0000x');
1002999
expect(inputElm).toBeInvalid();
@@ -1017,7 +1014,6 @@ describe('input', function() {
10171014

10181015
it('should validate in-lined pattern with modifiers', function() {
10191016
compileInput('<input type="text" ng-model="value" ng-pattern="/^abc?$/i" />');
1020-
scope.$digest();
10211017

10221018
changeInputValueTo('aB');
10231019
expect(inputElm).toBeValid();
@@ -1028,9 +1024,8 @@ describe('input', function() {
10281024

10291025

10301026
it('should validate pattern from scope', function() {
1031-
compileInput('<input type="text" ng-model="value" ng-pattern="regexp" />');
10321027
scope.regexp = /^\d\d\d-\d\d-\d\d\d\d$/;
1033-
scope.$digest();
1028+
compileInput('<input type="text" ng-model="value" ng-pattern="regexp" />');
10341029

10351030
changeInputValueTo('x000-00-0000x');
10361031
expect(inputElm).toBeInvalid();
@@ -1153,7 +1148,6 @@ describe('input', function() {
11531148
it('should come up blank when no value specified', function() {
11541149
compileInput('<input type="month" ng-model="test" />');
11551150

1156-
scope.$digest();
11571151
expect(inputElm.val()).toBe('');
11581152

11591153
scope.$apply(function() {
@@ -1181,7 +1175,6 @@ describe('input', function() {
11811175
describe('min', function (){
11821176
beforeEach(function (){
11831177
compileInput('<input type="month" ng-model="value" name="alias" min="2013-01" />');
1184-
scope.$digest();
11851178
});
11861179

11871180
it('should invalidate', function (){
@@ -1202,7 +1195,6 @@ describe('input', function() {
12021195
describe('max', function(){
12031196
beforeEach(function (){
12041197
compileInput('<input type="month" ng-model="value" name="alias" max="2013-01" />');
1205-
scope.$digest();
12061198
});
12071199

12081200
it('should validate', function (){
@@ -1279,7 +1271,6 @@ describe('input', function() {
12791271
it('should come up blank when no value specified', function() {
12801272
compileInput('<input type="week" ng-model="test" />');
12811273

1282-
scope.$digest();
12831274
expect(inputElm.val()).toBe('');
12841275

12851276
scope.$apply(function() {
@@ -1306,7 +1297,6 @@ describe('input', function() {
13061297
describe('min', function (){
13071298
beforeEach(function (){
13081299
compileInput('<input type="week" ng-model="value" name="alias" min="2013-W01" />');
1309-
scope.$digest();
13101300
});
13111301

13121302
it('should invalidate', function (){
@@ -1327,7 +1317,6 @@ describe('input', function() {
13271317
describe('max', function(){
13281318
beforeEach(function (){
13291319
compileInput('<input type="week" ng-model="value" name="alias" max="2013-W01" />');
1330-
scope.$digest();
13311320
});
13321321

13331322
it('should validate', function (){
@@ -1403,7 +1392,6 @@ describe('input', function() {
14031392
it('should come up blank when no value specified', function() {
14041393
compileInput('<input type="datetime-local" ng-model="test" />');
14051394

1406-
scope.$digest();
14071395
expect(inputElm.val()).toBe('');
14081396

14091397
scope.$apply(function() {
@@ -1430,7 +1418,6 @@ describe('input', function() {
14301418
describe('min', function (){
14311419
beforeEach(function (){
14321420
compileInput('<input type="datetime-local" ng-model="value" name="alias" min="2000-01-01T12:30" />');
1433-
scope.$digest();
14341421
});
14351422

14361423
it('should invalidate', function (){
@@ -1451,7 +1438,6 @@ describe('input', function() {
14511438
describe('max', function (){
14521439
beforeEach(function (){
14531440
compileInput('<input type="datetime-local" ng-model="value" name="alias" max="2019-01-01T01:02" />');
1454-
scope.$digest();
14551441
});
14561442

14571443
it('should invalidate', function (){
@@ -1472,7 +1458,6 @@ describe('input', function() {
14721458
it('should validate even if max value changes on-the-fly', function(done) {
14731459
scope.max = '2013-01-01T01:02';
14741460
compileInput('<input type="datetime-local" ng-model="value" name="alias" max="{{max}}" />');
1475-
scope.$digest();
14761461

14771462
changeInputValueTo('2014-01-01T12:34');
14781463
expect(inputElm).toBeInvalid();
@@ -1487,7 +1472,6 @@ describe('input', function() {
14871472
it('should validate even if min value changes on-the-fly', function(done) {
14881473
scope.min = '2013-01-01T01:02';
14891474
compileInput('<input type="datetime-local" ng-model="value" name="alias" min="{{min}}" />');
1490-
scope.$digest();
14911475

14921476
changeInputValueTo('2010-01-01T12:34');
14931477
expect(inputElm).toBeInvalid();
@@ -1557,7 +1541,6 @@ describe('input', function() {
15571541
it('should come up blank when no value specified', function() {
15581542
compileInput('<input type="time" ng-model="test" />');
15591543

1560-
scope.$digest();
15611544
expect(inputElm.val()).toBe('');
15621545

15631546
scope.$apply(function() {
@@ -1584,7 +1567,6 @@ describe('input', function() {
15841567
describe('min', function (){
15851568
beforeEach(function (){
15861569
compileInput('<input type="time" ng-model="value" name="alias" min="09:30" />');
1587-
scope.$digest();
15881570
});
15891571

15901572
it('should invalidate', function (){
@@ -1605,7 +1587,6 @@ describe('input', function() {
16051587
describe('max', function (){
16061588
beforeEach(function (){
16071589
compileInput('<input type="time" ng-model="value" name="alias" max="22:30" />');
1608-
scope.$digest();
16091590
});
16101591

16111592
it('should invalidate', function (){
@@ -1626,7 +1607,6 @@ describe('input', function() {
16261607
it('should validate even if max value changes on-the-fly', function(done) {
16271608
scope.max = '21:02';
16281609
compileInput('<input type="time" ng-model="value" name="alias" max="{{max}}" />');
1629-
scope.$digest();
16301610

16311611
changeInputValueTo('22:34');
16321612
expect(inputElm).toBeInvalid();
@@ -1641,7 +1621,6 @@ describe('input', function() {
16411621
it('should validate even if min value changes on-the-fly', function(done) {
16421622
scope.min = '08:45';
16431623
compileInput('<input type="time" ng-model="value" name="alias" min="{{min}}" />');
1644-
scope.$digest();
16451624

16461625
changeInputValueTo('06:15');
16471626
expect(inputElm).toBeInvalid();
@@ -1711,7 +1690,6 @@ describe('input', function() {
17111690
it('should come up blank when no value specified', function() {
17121691
compileInput('<input type="date" ng-model="test" />');
17131692

1714-
scope.$digest();
17151693
expect(inputElm.val()).toBe('');
17161694

17171695
scope.$apply(function() {
@@ -1738,7 +1716,6 @@ describe('input', function() {
17381716
describe('min', function (){
17391717
beforeEach(function (){
17401718
compileInput('<input type="date" ng-model="value" name="alias" min="2000-01-01" />');
1741-
scope.$digest();
17421719
});
17431720

17441721
it('should invalidate', function (){
@@ -1759,7 +1736,6 @@ describe('input', function() {
17591736
describe('max', function (){
17601737
beforeEach(function (){
17611738
compileInput('<input type="date" ng-model="value" name="alias" max="2019-01-01" />');
1762-
scope.$digest();
17631739
});
17641740

17651741
it('should invalidate', function (){
@@ -1780,7 +1756,6 @@ describe('input', function() {
17801756
it('should validate even if max value changes on-the-fly', function(done) {
17811757
scope.max = '2013-01-01';
17821758
compileInput('<input type="date" ng-model="value" name="alias" max="{{max}}" />');
1783-
scope.$digest();
17841759

17851760
changeInputValueTo('2014-01-01');
17861761
expect(inputElm).toBeInvalid();
@@ -1795,7 +1770,6 @@ describe('input', function() {
17951770
it('should validate even if min value changes on-the-fly', function(done) {
17961771
scope.min = '2013-01-01';
17971772
compileInput('<input type="date" ng-model="value" name="alias" min="{{min}}" />');
1798-
scope.$digest();
17991773

18001774
changeInputValueTo('2010-01-01');
18011775
expect(inputElm).toBeInvalid();
@@ -1846,7 +1820,6 @@ describe('input', function() {
18461820
it('should come up blank when no value specified', function() {
18471821
compileInput('<input type="number" ng-model="age" />');
18481822

1849-
scope.$digest();
18501823
expect(inputElm.val()).toBe('');
18511824

18521825
scope.$apply(function() {
@@ -1875,7 +1848,6 @@ describe('input', function() {
18751848

18761849
it('should validate', function() {
18771850
compileInput('<input type="number" ng-model="value" name="alias" min="10" />');
1878-
scope.$digest();
18791851

18801852
changeInputValueTo('1');
18811853
expect(inputElm).toBeInvalid();
@@ -1891,7 +1863,6 @@ describe('input', function() {
18911863
it('should validate even if min value changes on-the-fly', function(done) {
18921864
scope.min = 10;
18931865
compileInput('<input type="number" ng-model="value" name="alias" min="{{min}}" />');
1894-
scope.$digest();
18951866

18961867
changeInputValueTo('5');
18971868
expect(inputElm).toBeInvalid();
@@ -1909,7 +1880,6 @@ describe('input', function() {
19091880

19101881
it('should validate', function() {
19111882
compileInput('<input type="number" ng-model="value" name="alias" max="10" />');
1912-
scope.$digest();
19131883

19141884
changeInputValueTo('20');
19151885
expect(inputElm).toBeInvalid();
@@ -1925,7 +1895,6 @@ describe('input', function() {
19251895
it('should validate even if max value changes on-the-fly', function(done) {
19261896
scope.max = 10;
19271897
compileInput('<input type="number" ng-model="value" name="alias" max="{{max}}" />');
1928-
scope.$digest();
19291898

19301899
changeInputValueTo('5');
19311900
expect(inputElm).toBeValid();
@@ -2352,7 +2321,6 @@ describe('input', function() {
23522321

23532322
it('should set $invalid when model undefined', function() {
23542323
compileInput('<input type="text" ng-model="notDefined" required />');
2355-
scope.$digest();
23562324
expect(inputElm).toBeInvalid();
23572325
});
23582326

@@ -2406,7 +2374,6 @@ describe('input', function() {
24062374
compileInput('<input type="checkbox" ng-model="foo" ng-change="changeFn()">');
24072375

24082376
scope.changeFn = jasmine.createSpy('changeFn');
2409-
scope.$digest();
24102377
expect(scope.changeFn).not.toHaveBeenCalled();
24112378

24122379
browserTrigger(inputElm, 'click');
@@ -2433,7 +2400,6 @@ describe('input', function() {
24332400
compileInput('<input type="radio" ng-model="selected" ng-value="true">' +
24342401
'<input type="radio" ng-model="selected" ng-value="false">' +
24352402
'<input type="radio" ng-model="selected" ng-value="1">');
2436-
scope.$digest();
24372403

24382404
browserTrigger(inputElm[0], 'click');
24392405
expect(scope.selected).toBe(true);

0 commit comments

Comments
 (0)