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

chore(jshint): enforce jshint for tests #7264

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ module.exports = function(grunt) {
options: {
jshintrc: true,
},
tests: {
files: { src: 'test/**/*.js' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is best to use files[...] here so that we keep all file references in a single place, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see that we don't do it for the other modules!

},
ng: {
files: { src: files['angularSrc'] },
},
Expand Down
44 changes: 21 additions & 23 deletions test/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"sub": true,
"undef": true,
"browser": true,
"indent": 2,
"globals": {
/* auto/injector.js */
"createInjector": false,
Expand All @@ -42,7 +43,6 @@
"isArrayLike": false,
"forEach": false,
"sortedKeys": false,
"forEachSorted": false,
"reverseParams": false,
"nextUid": false,
"setHashKey": false,
Expand Down Expand Up @@ -102,9 +102,6 @@
"getter": false,
"getBlockElements": false,

/* filters.js */
"getFirstThursdayOfYear": false,

/* AngularPublic.js */
"version": false,
"publishExternalAPI": false,
Expand Down Expand Up @@ -147,24 +144,6 @@
"urlResolve": false,
"urlIsSameOrigin": false,

/* ng/compile.js */
"directiveNormalize": false,

/* ng/parse.js */
"setter": false,

/* ng/directive/directives.js */
"ngDirective": false,

/* ng/directive/input.js */
"VALID_CLASS": false,
"INVALID_CLASS": false,
"PRISTINE_CLASS": false,
"DIRTY_CLASS": false,

/* ng/directive/form.js */
"nullFormCtrl": false,

/* jasmine / karma */
"it": false,
"iit": false,
Expand All @@ -175,10 +154,29 @@
"expect": false,
"jasmine": false,
"spyOn": false,
"waits": false,
"waitsFor": false,
"runs": false,
"dump": false,

/* e2e */
"browser": false,
"element": false,
"by": false,

/* testabilityPatch / matchers */
"inject": false,
"module": false,
"dealoc": false
"dealoc": false,
"_jQuery": false,
"_jqLiteMode": false,
"sortedHtml": false,
"childrenTagsOf": false,
"assertHidden": false,
"assertVisible": false,
"provideLog": false,
"spyOnlyCallsWithArgs": false,
"createMockStyleSheet": false,
"browserTrigger": false
}
}
49 changes: 27 additions & 22 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('angular', function() {

it('should throw an exception when source and destination are equivalent', function() {
var src, dst;
src = dst = {key: 'value'};
src = dst = {key: 'value'};
expect(function() { copy(src, dst); }).toThrowMinErr("ng", "cpi", "Can't copy! Source and destination are identical.");
src = dst = [2, 4];
expect(function() { copy(src, dst); }).toThrowMinErr("ng", "cpi", "Can't copy! Source and destination are identical.");
Expand Down Expand Up @@ -149,7 +149,6 @@ describe('angular', function() {
});

describe("extend", function() {

it('should not copy the private $$hashKey', function() {
var src,dst;
src = {};
Expand Down Expand Up @@ -209,7 +208,7 @@ describe('angular', function() {

it('should omit properties from prototype chain', function() {
var original, clone = {};
function Func() {};
function Func() {}
Func.prototype.hello = "world";

original = new Func();
Expand Down Expand Up @@ -316,6 +315,7 @@ describe('angular', function() {
});

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


Expand All @@ -472,13 +472,14 @@ describe('angular', function() {
var obj = new MyObj(),
log = [];

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

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


it('should not break if obj is an array we override hasOwnProperty', function() {
/* jshint -W001 */
var obj = [];
obj[0] = 1;
obj[1] = 2;
Expand Down Expand Up @@ -506,7 +507,7 @@ describe('angular', function() {
log = [];


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

Expand All @@ -521,7 +522,7 @@ describe('angular', function() {
var htmlCollection = document.getElementsByName('x'),
log = [];

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

Expand All @@ -536,7 +537,7 @@ describe('angular', function() {
var htmlCollection = document.querySelectorAll('[name="x"]'),
log = [];

forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML)});
forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML); });
expect(log).toEqual(['0:a', '1:c']);
});
}
Expand All @@ -545,42 +546,42 @@ describe('angular', function() {
var args,
log = [];

(function(){ args = arguments}('a', 'b', 'c'));
(function(){ args = arguments; }('a', 'b', 'c'));

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

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

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


it('should handle objects with length property as objects', function() {
var obj = {
'foo' : 'bar',
'length': 2
},
log = [];
'foo' : 'bar',
'length': 2
},
log = [];

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


it('should handle objects of custom types with length property as objects', function() {
function CustomType() {
this.length = 2;
this.foo = 'bar'
this.foo = 'bar';
}

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

forEach(obj, function(value, key) { log.push(key + ':' + value)});
forEach(obj, function(value, key) { log.push(key + ':' + value); });
expect(log).toEqual(['length:2', 'foo:bar']);
});
});
Expand Down Expand Up @@ -748,9 +749,11 @@ describe('angular', function() {
var appElement = jqLite('<div ng-app="doesntexist"></div>')[0];

expect(function() {
angularInit(appElement, bootstrap);
angularInit(appElement, angular.bootstrap);
}).toThrowMatching(
/\[\$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\./
new RegExp('\\[\\$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\\.')
);
});

Expand Down Expand Up @@ -789,7 +792,7 @@ describe('angular', function() {
expect(bootstrapSpy.mostRecentCall.args[2].strictDi).toBe(true);

var injector = appElement.injector();
function testFactory($rootScope) {};
function testFactory($rootScope) {}
expect(function() {
injector.instantiate(testFactory);
}).toThrowMinErr('$injector', 'strictdi');
Expand Down Expand Up @@ -956,7 +959,9 @@ describe('angular', function() {
expect(function() {
angular.bootstrap(element, ['doesntexist']);
}).toThrowMatching(
/\[\$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\./);
new RegExp('\\[\\$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\\.'));

expect(element.html()).toBe('{{1+2}}');
dealoc(element);
Expand Down
Loading