Check for unused vars and params in specs

This commit is contained in:
Steve Gravrock
2022-04-16 10:58:25 -07:00
parent 364cf35474
commit 482dc883eb
20 changed files with 81 additions and 80 deletions

View File

@@ -7,10 +7,13 @@ module.exports = {
semi: 'off',
'key-spacing': 'off',
'space-before-blocks': 'off',
'no-unused-vars': 'off',
'no-trailing-spaces': 'off',
'block-spacing': 'off',
// Additionally, check for unused fn args
// TODO: consider doing this in src files as well as specs
'no-unused-vars': ['error', { args: 'after-used' }],
// Since linting is done at the end of the process and doesn't stop us
// from running tests, it makes sense to fail if debugger statements
// or console references are present.

View File

@@ -781,6 +781,6 @@ describe('AsyncExpectation', function() {
});
function dummyPromise() {
return new Promise(function(resolve, reject) {});
return new Promise(function() {});
}
});

View File

@@ -960,8 +960,7 @@ describe('Clock (acceptance)', function() {
return delayedFunctionScheduler;
},
mockDate
),
env = jasmineUnderTest.getEnv();
);
expect(() => clock.mockDate(12345)).toThrowError(
'The argument to jasmine.clock().mockDate(), if specified, should be ' +

View File

@@ -212,7 +212,6 @@ describe('Deprecator', function() {
'addDeprecationWarning',
'getFullName'
]);
var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter();
var deprecation, originalStack;
try {

View File

@@ -193,6 +193,7 @@ describe('Env', function() {
it('throws an error when given arguments', function() {
expect(function() {
// eslint-disable-next-line no-unused-vars
env.describe('done method', function(done) {});
}).toThrowError('describe does not expect any arguments');
});

View File

@@ -500,7 +500,7 @@ describe('PrettyPrinter', function() {
describe('Custom object formatters', function() {
it('should use the first custom object formatter that does not return undefined', function() {
var customObjectFormatters = [
function(obj) {
function() {
return undefined;
},
function(obj) {
@@ -518,7 +518,7 @@ describe('PrettyPrinter', function() {
it('should fall back to built in logic if all custom object formatters return undefined', function() {
var customObjectFormatters = [
function(obj) {
function() {
return undefined;
}
],
@@ -532,7 +532,7 @@ describe('PrettyPrinter', function() {
describe('#customFormat_', function() {
it('should use the first custom object formatter that does not return undefined', function() {
var customObjectFormatters = [
function(obj) {
function() {
return undefined;
},
function(obj) {
@@ -550,7 +550,7 @@ describe('PrettyPrinter', function() {
it('should return undefined if all custom object formatters return undefined', function() {
var customObjectFormatters = [
function(obj) {
function() {
return undefined;
}
],

View File

@@ -262,6 +262,7 @@ describe('QueueRunner', function() {
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
var timeout = 3,
// eslint-disable-next-line no-unused-vars
beforeFn = { fn: function(done) {}, type: 'before', timeout: timeout },
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
onComplete = jasmine.createSpy('onComplete'),
@@ -309,6 +310,7 @@ describe('QueueRunner', function() {
});
it('by default does not set a timeout for asynchronous functions', function() {
// eslint-disable-next-line no-unused-vars
var beforeFn = { fn: function(done) {} },
queueableFn = { fn: jasmine.createSpy('fn') },
onComplete = jasmine.createSpy('onComplete'),
@@ -331,6 +333,7 @@ describe('QueueRunner', function() {
it('clears the timeout when an async function throws an exception, to prevent additional exception reporting', function() {
var queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
throw new Error('error!');
}
@@ -434,6 +437,7 @@ describe('QueueRunner', function() {
it('continues running functions when an exception is thrown in async code without timing out', function() {
var queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
throwAsync();
},
@@ -605,6 +609,7 @@ describe('QueueRunner', function() {
it('issues an error if the function also takes a parameter', function() {
var queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
return new StubPromise();
}
@@ -691,6 +696,7 @@ describe('QueueRunner', function() {
it('continues running the functions even after an exception is thrown in an async spec', function() {
var queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
throw new Error('error');
}

View File

@@ -337,7 +337,7 @@ describe('SpyRegistry', function() {
});
Object.defineProperty(subject, 'notSpied4', {
configurable: false,
set: function(val) {
set: function() {
/**/
},
get: function() {

View File

@@ -97,11 +97,17 @@ describe('Spies', function() {
it('preserves arity of original function', function() {
var functions = [
function nullary() {},
// eslint-disable-next-line no-unused-vars
function unary(arg) {},
// eslint-disable-next-line no-unused-vars
function binary(arg1, arg2) {},
// eslint-disable-next-line no-unused-vars
function ternary(arg1, arg2, arg3) {},
// eslint-disable-next-line no-unused-vars
function quaternary(arg1, arg2, arg3, arg4) {},
// eslint-disable-next-line no-unused-vars
function quinary(arg1, arg2, arg3, arg4, arg5) {},
// eslint-disable-next-line no-unused-vars
function senary(arg1, arg2, arg3, arg4, arg5, arg6) {}
];

View File

@@ -82,7 +82,7 @@ describe('TreeProcessor', function() {
processor = new jasmineUnderTest.TreeProcessor({
tree: leaf,
runnableIds: [leaf.id],
excludeNode: function(node) {
excludeNode: function() {
return true;
}
}),

View File

@@ -39,7 +39,7 @@ describe('jasmineUnderTest.util', function() {
};
beforeEach(function() {
mockNativePromise = new Promise(function(res, rej) {});
mockNativePromise = new Promise(function() {});
mockPromiseLikeObject = new mockPromiseLike();
});

View File

@@ -1,5 +1,5 @@
describe('Asymmetric equality testers (Integration)', function() {
function verifyPasses(expectations, setup) {
function verifyPasses(expectations) {
it('passes', function(done) {
var env = new jasmineUnderTest.Env();
env.it('a spec', function() {

View File

@@ -85,7 +85,7 @@ describe('Custom Async Matchers (Integration)', function() {
});
it('passes the jasmine utility to the matcher factory', function(done) {
var matcherFactory = function(util) {
var matcherFactory = function() {
return {
compare: function() {
return Promise.resolve({ pass: true });

View File

@@ -1,6 +1,5 @@
describe('Custom Matchers (Integration)', function() {
var env;
var fakeTimer;
beforeEach(function() {
env = new jasmineUnderTest.Env();
@@ -211,7 +210,7 @@ describe('Custom Matchers (Integration)', function() {
});
it('passes the jasmine utility to the matcher factory', function(done) {
var matcherFactory = function(util) {
var matcherFactory = function() {
return {
compare: function() {
return { pass: true };

View File

@@ -792,6 +792,7 @@ describe('Env integration', function() {
env.describe('my suite', function() {
env.it('my spec', function() {});
// eslint-disable-next-line no-unused-vars
env.afterAll(function(afterAllDone) {
throw error;
});
@@ -959,9 +960,7 @@ describe('Env integration', function() {
it('Allows filtering out specs and suites to run programmatically', function(done) {
var calls = [],
suiteCallback = jasmine.createSpy('suite callback'),
firstSpec,
secondSuite;
suiteCallback = jasmine.createSpy('suite callback');
env.addReporter({ suiteDone: suiteCallback });
@@ -974,7 +973,7 @@ describe('Env integration', function() {
});
});
secondSuite = env.describe('second suite', function() {
env.describe('second suite', function() {
env.it('third spec', function() {
calls.push('third spec');
});
@@ -1086,8 +1085,6 @@ describe('Env integration', function() {
env.it('spec 0', function() {
env.spyOn(foo, 'bar');
var error = null;
expect(function() {
env.spyOn(foo, 'bar');
}).not.toThrow();
@@ -1296,6 +1293,7 @@ describe('Env integration', function() {
env.addReporter(reporter);
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 8414;
// eslint-disable-next-line no-unused-vars
env.it("async spec that doesn't call done", function(underTestCallback) {
env.expect(true).toBeTruthy();
jasmine.clock().tick(8416);
@@ -1374,6 +1372,7 @@ describe('Env integration', function() {
}, 100);
});
env.describe('beforeAll', function() {
// eslint-disable-next-line no-unused-vars
env.beforeAll(function(innerDone) {
realSetTimeout(function() {
jasmine.clock().tick(5001);
@@ -1389,6 +1388,7 @@ describe('Env integration', function() {
});
env.describe('afterAll', function() {
// eslint-disable-next-line no-unused-vars
env.afterAll(function(innerDone) {
realSetTimeout(function() {
jasmine.clock().tick(2001);
@@ -1404,6 +1404,7 @@ describe('Env integration', function() {
});
env.describe('beforeEach', function() {
// eslint-disable-next-line no-unused-vars
env.beforeEach(function(innerDone) {
realSetTimeout(function() {
jasmine.clock().tick(1001);
@@ -1419,6 +1420,7 @@ describe('Env integration', function() {
});
env.describe('afterEach', function() {
// eslint-disable-next-line no-unused-vars
env.afterEach(function(innerDone) {
realSetTimeout(function() {
jasmine.clock().tick(4001);
@@ -1435,6 +1437,7 @@ describe('Env integration', function() {
env.it(
'it times out',
// eslint-disable-next-line no-unused-vars
function(innerDone) {
realSetTimeout(function() {
jasmine.clock().tick(6001);
@@ -1910,7 +1913,7 @@ describe('Env integration', function() {
env.describe('testing custom equality testers', function() {
env.it('with a custom tester', function() {
env.addCustomEqualityTester(function(a, b) {
env.addCustomEqualityTester(function() {
return true;
});
env.expect('a').toEqual('b');
@@ -1940,7 +1943,7 @@ describe('Env integration', function() {
env.describe('testing custom equality testers', function() {
env.beforeAll(function() {
env.addCustomEqualityTester(function(a, b) {
env.addCustomEqualityTester(function() {
return true;
});
});
@@ -1981,7 +1984,7 @@ describe('Env integration', function() {
env.describe('testing custom equality testers', function() {
env.it('with a custom tester', function() {
env.addCustomEqualityTester(function(a, b) {
env.addCustomEqualityTester(function() {
return true;
});
env.expect(['a']).toContain('b');
@@ -2026,7 +2029,7 @@ describe('Env integration', function() {
env.describe('testing custom equality testers', function() {
env.beforeAll(function() {
env.addCustomEqualityTester(function(a, b) {
env.addCustomEqualityTester(function() {
return true;
});
});
@@ -2128,13 +2131,12 @@ describe('Env integration', function() {
});
it('throws an exception if you try to add a matcher outside of a runnable', function(done) {
var obj = { fn: function() {} },
exception;
let exception;
env.describe('a suite', function() {
try {
env.addMatchers({
myMatcher: function(actual, expected) {
myMatcher: function() {
return false;
}
});
@@ -2153,12 +2155,11 @@ describe('Env integration', function() {
});
it('throws an exception if you try to add a custom equality outside of a runnable', function(done) {
var obj = { fn: function() {} },
exception;
let exception;
env.describe('a suite', function() {
try {
env.addCustomEqualityTester(function(first, second) {
env.addCustomEqualityTester(function() {
return true;
});
} catch (e) {
@@ -2265,6 +2266,7 @@ describe('Env integration', function() {
env.addReporter(reporter);
env.describe('async suite', function() {
// eslint-disable-next-line no-unused-vars
env.afterAll(function(innerDone) {
setTimeout(function() {
throw new Error('suite');
@@ -2277,6 +2279,7 @@ describe('Env integration', function() {
env.describe('suite', function() {
env.it(
'async spec',
// eslint-disable-next-line no-unused-vars
function(innerDone) {
setTimeout(function() {
throw new Error('spec');
@@ -2877,7 +2880,7 @@ describe('Env integration', function() {
function fail(innerDone) {
var resolve;
var p = new Promise(function(res, rej) {
var p = new Promise(function(res) {
resolve = res;
});
env
@@ -3328,19 +3331,15 @@ describe('Env integration', function() {
});
it('sends debug logs to the reporter when the spec fails', function(done) {
var reporter = jasmine.createSpyObj('reporter', ['specDone']),
startTime,
endTime;
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
env.configure({ random: false });
env.it('fails', function() {
startTime = new Date().getTime();
env.debugLog('message 1');
env.debugLog('message 2');
env.expect(1).toBe(2);
endTime = new Date().getTime();
});
env.it('passes', function() {
@@ -3353,7 +3352,7 @@ describe('Env integration', function() {
asymmetricMatch: function(compareTo) {
return compareTo >= min && compareTo <= max;
},
jasmineToString: function(pp) {
jasmineToString: function() {
return '<number from ' + min + ' to ' + max + ' inclusive>';
}
};

View File

@@ -678,7 +678,6 @@ describe('Matchers (Integration)', function() {
return '|' + val + '|';
},
expectations: function(env) {
var spy = env.createSpy('foo');
env
.expect(function() {
throw 'x';
@@ -707,7 +706,6 @@ describe('Matchers (Integration)', function() {
return '|' + val + '|';
},
expectations: function(env) {
var spy = env.createSpy('foo');
env
.expect(function() {
throw 'x';
@@ -740,7 +738,6 @@ describe('Matchers (Integration)', function() {
return '|' + val + '|';
},
expectations: function(env) {
var spy = env.createSpy('foo');
env
.expect(function() {
throw new Error('nope');

View File

@@ -35,7 +35,7 @@ describe('spec running', function() {
var bar = 0;
var baz = 0;
var quux = 0;
var nested = env.describe('suite', function() {
env.describe('suite', function() {
env.describe('nested', function() {
env.it('should run nested suites', function() {
foo++;
@@ -497,12 +497,12 @@ describe('spec running', function() {
});
it("shouldn't run disabled suites", function(done) {
var specInADisabledSuite = jasmine.createSpy('specInADisabledSuite'),
suite = env.describe('A Suite', function() {
env.xdescribe('with a disabled suite', function() {
env.it('spec inside a disabled suite', specInADisabledSuite);
});
const specInADisabledSuite = jasmine.createSpy('specInADisabledSuite');
env.describe('A Suite', function() {
env.xdescribe('with a disabled suite', function() {
env.it('spec inside a disabled suite', specInADisabledSuite);
});
});
env.execute(null, function() {
expect(specInADisabledSuite).not.toHaveBeenCalled();
@@ -511,16 +511,16 @@ describe('spec running', function() {
});
it("shouldn't run before/after functions in disabled suites", function(done) {
var shouldNotRun = jasmine.createSpy('shouldNotRun'),
suite = env.xdescribe('A disabled Suite', function() {
// None of the before/after functions should run.
env.beforeAll(shouldNotRun);
env.beforeEach(shouldNotRun);
env.afterEach(shouldNotRun);
env.afterAll(shouldNotRun);
var shouldNotRun = jasmine.createSpy('shouldNotRun');
env.xdescribe('A disabled Suite', function() {
// None of the before/after functions should run.
env.beforeAll(shouldNotRun);
env.beforeEach(shouldNotRun);
env.afterEach(shouldNotRun);
env.afterAll(shouldNotRun);
env.it('spec inside a disabled suite', shouldNotRun);
});
env.it('spec inside a disabled suite', shouldNotRun);
});
env.execute(null, function() {
expect(shouldNotRun).not.toHaveBeenCalled();
@@ -547,11 +547,10 @@ describe('spec running', function() {
});
it('should set all pending specs to pending when a suite is run', function(done) {
var pendingSpec,
suite = env.describe('default current suite', function() {
pendingSpec = env.it('I am a pending spec');
}),
reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.describe('default current suite', function() {
env.it('I am a pending spec');
});
const reporter = jasmine.createSpyObj('reporter', ['specDone']);
env.addReporter(reporter);
@@ -886,6 +885,7 @@ describe('spec running', function() {
const actions = [];
env.describe('Something', function() {
// eslint-disable-next-line no-unused-vars
env.beforeEach(function(innerDone) {
actions.push('beforeEach');
}, 1);
@@ -1299,8 +1299,7 @@ describe('spec running', function() {
describe('when stopOnSpecFailure is on', function() {
it('does not run further specs when one fails', function(done) {
var actions = [],
config;
const actions = [];
env.describe('wrapper', function() {
env.it('fails', function() {

View File

@@ -392,7 +392,7 @@ describe('matchersUtil', function() {
it('passes when an asymmetric equality tester returns true', function() {
var tester = {
asymmetricMatch: function(other) {
asymmetricMatch: function() {
return true;
}
},
@@ -404,7 +404,7 @@ describe('matchersUtil', function() {
it('fails when an asymmetric equality tester returns false', function() {
var tester = {
asymmetricMatch: function(other) {
asymmetricMatch: function() {
return false;
}
},
@@ -424,7 +424,7 @@ describe('matchersUtil', function() {
});
it('passes when a custom equality matcher returns true', function() {
var tester = function(a, b) {
var tester = function() {
return true;
},
matchersUtil = new jasmineUnderTest.MatchersUtil({
@@ -441,7 +441,7 @@ describe('matchersUtil', function() {
});
describe("when a custom equality matcher returns 'undefined'", function() {
var tester = function(a, b) {
var tester = function() {
return jasmine.undefined;
};
@@ -455,7 +455,7 @@ describe('matchersUtil', function() {
});
it('fails for equivalents when a custom equality matcher returns false', function() {
var tester = function(a, b) {
var tester = function() {
return false;
},
matchersUtil = new jasmineUnderTest.MatchersUtil({
@@ -468,11 +468,11 @@ describe('matchersUtil', function() {
it('passes for an asymmetric equality tester that returns true when a custom equality tester return false', function() {
var asymmetricTester = {
asymmetricMatch: function(other) {
asymmetricMatch: function() {
return true;
}
},
symmetricTester = function(a, b) {
symmetricTester = function() {
return false;
},
matchersUtil = new jasmineUnderTest.MatchersUtil({
@@ -1009,7 +1009,7 @@ describe('matchersUtil', function() {
});
it('uses custom equality testers if actual is an Array', function() {
var customTester = function(a, b) {
var customTester = function() {
return true;
},
matchersUtil = new jasmineUnderTest.MatchersUtil({

View File

@@ -368,9 +368,6 @@ describe('toEqual', function() {
});
it('reports mismatches between objects with their own constructor property', function() {
function Foo() {}
function Bar() {}
var actual = { x: { constructor: 'blerf' } },
expected = { x: { constructor: 'ftarrh' } },
message = "Expected $.x.constructor = 'blerf' to equal 'ftarrh'.";
@@ -379,9 +376,6 @@ describe('toEqual', function() {
});
it('reports mismatches between an object with a real constructor and one with its own constructor property', function() {
function Foo() {}
function Bar() {}
var actual = { x: {} },
expected = { x: { constructor: 'ftarrh' } },
message =

View File

@@ -18,8 +18,7 @@ describe('toHaveBeenCalledTimes', function() {
it('fails when expected numbers is not supplied', function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
spy = new jasmineUnderTest.Spy('spy'),
result;
spy = new jasmineUnderTest.Spy('spy');
spy();
expect(function() {