Skip to content

Commit a0fad24

Browse files
shahatarodyhaddad
authored andcommitted
chore(jshint): enforce jshint for tests
Closes angular#8023 Closes angular#8026
1 parent da0e3c9 commit a0fad24

70 files changed

Lines changed: 979 additions & 819 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gruntfile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ module.exports = function(grunt) {
107107
options: {
108108
jshintrc: true,
109109
},
110+
tests: {
111+
files: { src: 'test/**/*.js' },
112+
},
110113
ng: {
111114
files: { src: files['angularSrc'] },
112115
},

test/.jshintrc

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"sub": true,
1717
"undef": true,
1818
"browser": true,
19+
"indent": 2,
1920
"globals": {
2021
/* auto/injector.js */
2122
"createInjector": false,
@@ -42,7 +43,6 @@
4243
"isArrayLike": false,
4344
"forEach": false,
4445
"sortedKeys": false,
45-
"forEachSorted": false,
4646
"reverseParams": false,
4747
"nextUid": false,
4848
"setHashKey": false,
@@ -103,9 +103,6 @@
103103
"getBlockElements": false,
104104
"VALIDITY_STATE_PROPERTY": true,
105105

106-
/* filters.js */
107-
"getFirstThursdayOfYear": false,
108-
109106
/* AngularPublic.js */
110107
"version": false,
111108
"publishExternalAPI": false,
@@ -148,24 +145,6 @@
148145
"urlResolve": false,
149146
"urlIsSameOrigin": false,
150147

151-
/* ng/compile.js */
152-
"directiveNormalize": false,
153-
154-
/* ng/parse.js */
155-
"setter": false,
156-
157-
/* ng/directive/directives.js */
158-
"ngDirective": false,
159-
160-
/* ng/directive/input.js */
161-
"VALID_CLASS": false,
162-
"INVALID_CLASS": false,
163-
"PRISTINE_CLASS": false,
164-
"DIRTY_CLASS": false,
165-
166-
/* ng/directive/form.js */
167-
"nullFormCtrl": false,
168-
169148
/* jasmine / karma */
170149
"it": false,
171150
"iit": false,
@@ -176,10 +155,30 @@
176155
"expect": false,
177156
"jasmine": false,
178157
"spyOn": false,
158+
"waits": false,
159+
"waitsFor": false,
160+
"runs": false,
161+
"dump": false,
162+
163+
/* e2e */
164+
"browser": false,
165+
"element": false,
166+
"by": false,
179167

180168
/* testabilityPatch / matchers */
181169
"inject": false,
182170
"module": false,
183-
"dealoc": false
171+
"dealoc": false,
172+
"dealoc": false,
173+
"_jQuery": false,
174+
"_jqLiteMode": false,
175+
"sortedHtml": false,
176+
"childrenTagsOf": false,
177+
"assertHidden": false,
178+
"assertVisible": false,
179+
"provideLog": false,
180+
"spyOnlyCallsWithArgs": false,
181+
"createMockStyleSheet": false,
182+
"browserTrigger": false
184183
}
185184
}

test/AngularSpec.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('angular', function() {
118118

119119
it('should throw an exception when source and destination are equivalent', function() {
120120
var src, dst;
121-
src = dst = {key: 'value'};
121+
src = dst = {key: 'value'};
122122
expect(function() { copy(src, dst); }).toThrowMinErr("ng", "cpi", "Can't copy! Source and destination are identical.");
123123
src = dst = [2, 4];
124124
expect(function() { copy(src, dst); }).toThrowMinErr("ng", "cpi", "Can't copy! Source and destination are identical.");
@@ -223,7 +223,7 @@ describe('angular', function() {
223223

224224
it('should omit properties from prototype chain', function() {
225225
var original, clone = {};
226-
function Func() {};
226+
function Func() {}
227227
Func.prototype.hello = "world";
228228

229229
original = new Func();
@@ -349,6 +349,7 @@ describe('angular', function() {
349349
});
350350

351351
it('should correctly test for keys that are present on Object.prototype', function() {
352+
/* jshint -W001 */
352353
// MS IE8 just doesn't work for this kind of thing, since "for ... in" doesn't return
353354
// things like hasOwnProperty even if it is explicitly defined on the actual object!
354355
if (msie<=8) return;
@@ -497,7 +498,7 @@ describe('angular', function() {
497498
expect(toKeyValue({key: [323,'value',true]})).toEqual('key=323&key=value&key');
498499
expect(toKeyValue({key: [323,'value',true, 1234]})).
499500
toEqual('key=323&key=value&key&key=1234');
500-
});
501+
});
501502
});
502503

503504

@@ -512,13 +513,14 @@ describe('angular', function() {
512513
var obj = new MyObj(),
513514
log = [];
514515

515-
forEach(obj, function(value, key) { log.push(key + ':' + value)});
516+
forEach(obj, function(value, key) { log.push(key + ':' + value); });
516517

517518
expect(log).toEqual(['bar:barVal', 'baz:bazVal']);
518519
});
519520

520521

521522
it('should not break if obj is an array we override hasOwnProperty', function() {
523+
/* jshint -W001 */
522524
var obj = [];
523525
obj[0] = 1;
524526
obj[1] = 2;
@@ -546,7 +548,7 @@ describe('angular', function() {
546548
log = [];
547549

548550

549-
forEach(nodeList, function(value, key) { log.push(key + ':' + value.innerHTML)});
551+
forEach(nodeList, function(value, key) { log.push(key + ':' + value.innerHTML); });
550552
expect(log).toEqual(['0:a', '1:b', '2:c']);
551553
});
552554

@@ -561,7 +563,7 @@ describe('angular', function() {
561563
var htmlCollection = document.getElementsByName('x'),
562564
log = [];
563565

564-
forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML)});
566+
forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML); });
565567
expect(log).toEqual(['0:a', '1:c']);
566568
});
567569

@@ -576,7 +578,7 @@ describe('angular', function() {
576578
var htmlCollection = document.querySelectorAll('[name="x"]'),
577579
log = [];
578580

579-
forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML)});
581+
forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML); });
580582
expect(log).toEqual(['0:a', '1:c']);
581583
});
582584
}
@@ -585,42 +587,42 @@ describe('angular', function() {
585587
var args,
586588
log = [];
587589

588-
(function(){ args = arguments}('a', 'b', 'c'));
590+
(function(){ args = arguments; }('a', 'b', 'c'));
589591

590-
forEach(args, function(value, key) { log.push(key + ':' + value)});
592+
forEach(args, function(value, key) { log.push(key + ':' + value); });
591593
expect(log).toEqual(['0:a', '1:b', '2:c']);
592594
});
593595

594596
it('should handle string values like arrays', function() {
595597
var log = [];
596598

597-
forEach('bar', function(value, key) { log.push(key + ':' + value)});
599+
forEach('bar', function(value, key) { log.push(key + ':' + value); });
598600
expect(log).toEqual(['0:b', '1:a', '2:r']);
599601
});
600602

601603

602604
it('should handle objects with length property as objects', function() {
603605
var obj = {
604-
'foo' : 'bar',
605-
'length': 2
606-
},
607-
log = [];
606+
'foo' : 'bar',
607+
'length': 2
608+
},
609+
log = [];
608610

609-
forEach(obj, function(value, key) { log.push(key + ':' + value)});
611+
forEach(obj, function(value, key) { log.push(key + ':' + value); });
610612
expect(log).toEqual(['foo:bar', 'length:2']);
611613
});
612614

613615

614616
it('should handle objects of custom types with length property as objects', function() {
615617
function CustomType() {
616618
this.length = 2;
617-
this.foo = 'bar'
619+
this.foo = 'bar';
618620
}
619621

620622
var obj = new CustomType(),
621623
log = [];
622624

623-
forEach(obj, function(value, key) { log.push(key + ':' + value)});
625+
forEach(obj, function(value, key) { log.push(key + ':' + value); });
624626
expect(log).toEqual(['length:2', 'foo:bar']);
625627
});
626628
});
@@ -790,7 +792,9 @@ describe('angular', function() {
790792
expect(function() {
791793
angularInit(appElement, bootstrap);
792794
}).toThrowMatching(
793-
/\[\$injector:modulerr] Failed to instantiate module doesntexist due to:\n.*\[\$injector:nomod] Module 'doesntexist' is not available! You either misspelled the module name or forgot to load it\./
795+
new RegExp('\\[\\$injector:modulerr] Failed to instantiate module doesntexist due to:\\n' +
796+
'.*\\[\\$injector:nomod] Module \'doesntexist\' is not available! You either ' +
797+
'misspelled the module name or forgot to load it\\.')
794798
);
795799
});
796800

@@ -818,7 +822,7 @@ describe('angular', function() {
818822
);
819823

820824
dealoc(document);
821-
})
825+
});
822826
});
823827

824828

@@ -979,7 +983,9 @@ describe('angular', function() {
979983
expect(function() {
980984
angular.bootstrap(element, ['doesntexist']);
981985
}).toThrowMatching(
982-
/\[\$injector:modulerr\] Failed to instantiate module doesntexist due to:\n.*\[\$injector:nomod\] Module 'doesntexist' is not available! You either misspelled the module name or forgot to load it\./);
986+
new RegExp('\\[\\$injector:modulerr\\] Failed to instantiate module doesntexist due to:\\n' +
987+
'.*\\[\\$injector:nomod\\] Module \'doesntexist\' is not available! You either ' +
988+
'misspelled the module name or forgot to load it\\.'));
983989

984990
expect(element.html()).toBe('{{1+2}}');
985991
dealoc(element);

test/BinderSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe('Binder', function() {
176176
var errorLogs = $exceptionHandler.errors;
177177

178178
$rootScope.error = {
179-
'throw': function() {throw 'ErrorMsg1';}
179+
'throw': function() {throw 'ErrorMsg1';}
180180
};
181181
$rootScope.$apply();
182182

0 commit comments

Comments
 (0)