Use const/let in specs, not var

This commit is contained in:
Steve Gravrock
2022-04-16 13:41:44 -07:00
parent 482dc883eb
commit 1166d10e43
111 changed files with 2522 additions and 2675 deletions

View File

@@ -1,6 +1,6 @@
describe('QueueRunner', function() {
it("runs all the functions it's passed", function() {
var calls = [],
const calls = [],
queueableFn1 = { fn: jasmine.createSpy('fn1') },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
queueRunner = new jasmineUnderTest.QueueRunner({
@@ -19,9 +19,10 @@ describe('QueueRunner', function() {
});
it("calls each function with a consistent 'this'-- an empty object", function() {
var queueableFn1 = { fn: jasmine.createSpy('fn1') },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
queueableFn3 = {
const queueableFn1 = { fn: jasmine.createSpy('fn1') };
const queueableFn2 = { fn: jasmine.createSpy('fn2') };
let asyncContext;
const queueableFn3 = {
fn: function(done) {
asyncContext = this;
done();
@@ -29,12 +30,11 @@ describe('QueueRunner', function() {
},
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn1, queueableFn2, queueableFn3]
}),
asyncContext;
});
queueRunner.execute();
var context = queueableFn1.fn.calls.first().object;
const context = queueableFn1.fn.calls.first().object;
expect(context).toEqual(new jasmineUnderTest.UserContext());
expect(queueableFn2.fn.calls.first().object).toBe(context);
expect(asyncContext).toBe(context);
@@ -53,7 +53,7 @@ describe('QueueRunner', function() {
//TODO: it would be nice if spy arity could match the fake, so we could do something like:
//createSpy('asyncfn').and.callFake(function(done) {});
var onComplete = jasmine.createSpy('onComplete'),
const onComplete = jasmine.createSpy('onComplete'),
beforeCallback = jasmine.createSpy('beforeCallback'),
fnCallback = jasmine.createSpy('fnCallback'),
afterCallback = jasmine.createSpy('afterCallback'),
@@ -104,7 +104,7 @@ describe('QueueRunner', function() {
});
it('explicitly fails an async function with a provided fail function and moves to the next function', function() {
var queueableFn1 = {
const queueableFn1 = {
fn: function(done) {
setTimeout(function() {
done.fail('foo');
@@ -131,7 +131,7 @@ describe('QueueRunner', function() {
describe('When next is called with an argument', function() {
it('explicitly fails and moves to the next function', function() {
var err = 'anything except undefined',
const err = 'anything except undefined',
queueableFn1 = {
fn: function(done) {
setTimeout(function() {
@@ -165,7 +165,7 @@ describe('QueueRunner', function() {
// except on a major release and with a deprecation warning in
// advance.
it('explicitly fails and moves to the next function', function(done) {
var err = new Error('foo'),
const err = new Error('foo'),
queueableFn1 = {
fn: function() {
return Promise.resolve(err);
@@ -187,7 +187,7 @@ describe('QueueRunner', function() {
});
it('does not log a deprecation', function(done) {
var err = new Error('foo'),
const err = new Error('foo'),
queueableFn1 = {
fn: function() {
return Promise.resolve(err);
@@ -209,7 +209,7 @@ describe('QueueRunner', function() {
describe('and the argument is not an Error', function() {
it('does not log a deprecation or report a failure', function(done) {
var queueableFn1 = {
const queueableFn1 = {
fn: function() {
return Promise.resolve('not an error');
}
@@ -234,7 +234,7 @@ describe('QueueRunner', function() {
});
it('does not cause an explicit fail if execution is being stopped', function() {
var err = new jasmineUnderTest.StopExecutionError('foo'),
const err = new jasmineUnderTest.StopExecutionError('foo'),
queueableFn1 = {
fn: function(done) {
setTimeout(function() {
@@ -261,7 +261,7 @@ describe('QueueRunner', function() {
});
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
var timeout = 3,
const timeout = 3,
// eslint-disable-next-line no-unused-vars
beforeFn = { fn: function(done) {}, type: 'before', timeout: timeout },
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
@@ -284,22 +284,22 @@ describe('QueueRunner', function() {
});
it('does not call onMultipleDone if an asynchrnous function completes after timing out', function() {
var timeout = 3,
queueableFn = {
fn: function(done) {
queueableFnDone = done;
},
type: 'queueable',
timeout: timeout
const timeout = 3;
let queueableFnDone;
const queueableFn = {
fn: function(done) {
queueableFnDone = done;
},
onComplete = jasmine.createSpy('onComplete'),
onMultipleDone = jasmine.createSpy('onMultipleDone'),
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn],
onComplete: onComplete,
onMultipleDone: onMultipleDone
}),
queueableFnDone;
type: 'queueable',
timeout: timeout
};
const onComplete = jasmine.createSpy('onComplete');
const onMultipleDone = jasmine.createSpy('onMultipleDone');
const queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn],
onComplete: onComplete,
onMultipleDone: onMultipleDone
});
queueRunner.execute();
jasmine.clock().tick(timeout);
@@ -311,7 +311,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) {} },
const beforeFn = { fn: function(done) {} },
queueableFn = { fn: jasmine.createSpy('fn') },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
@@ -332,7 +332,7 @@ describe('QueueRunner', function() {
});
it('clears the timeout when an async function throws an exception, to prevent additional exception reporting', function() {
var queueableFn = {
const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
throw new Error('error!');
@@ -356,7 +356,7 @@ describe('QueueRunner', function() {
});
it('clears the timeout when the done callback is called', function() {
var queueableFn = {
const queueableFn = {
fn: function(done) {
done();
}
@@ -379,7 +379,7 @@ describe('QueueRunner', function() {
});
it('only moves to the next spec the first time you call done', function() {
var queueableFn = {
const queueableFn = {
fn: function(done) {
done();
done();
@@ -399,7 +399,7 @@ describe('QueueRunner', function() {
});
it('does not move to the next spec if done is called after an exception has ended the spec', function() {
var queueableFn = {
const queueableFn = {
fn: function(done) {
setTimeout(done, 1);
throw new Error('error!');
@@ -421,22 +421,22 @@ describe('QueueRunner', function() {
it('should return a null when you call done', function() {
// Some promises want handlers to return anything but undefined to help catch "forgotten returns".
var doneReturn,
queueableFn = {
fn: function(done) {
doneReturn = done();
}
},
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn]
});
let doneReturn;
const queueableFn = {
fn: function(done) {
doneReturn = done();
}
};
const queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn]
});
queueRunner.execute();
expect(doneReturn).toBe(null);
});
it('continues running functions when an exception is thrown in async code without timing out', function() {
var queueableFn = {
const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
throwAsync();
@@ -488,7 +488,7 @@ describe('QueueRunner', function() {
});
it('handles exceptions thrown while waiting for the stack to clear', function() {
var queueableFn = {
const queueableFn = {
fn: function(done) {
done();
}
@@ -539,7 +539,7 @@ describe('QueueRunner', function() {
});
it('runs the function asynchronously, advancing once the promise is settled', function() {
var onComplete = jasmine.createSpy('onComplete'),
const onComplete = jasmine.createSpy('onComplete'),
fnCallback = jasmine.createSpy('fnCallback'),
p1 = new StubPromise(),
p2 = new StubPromise(),
@@ -580,7 +580,7 @@ describe('QueueRunner', function() {
});
it('handles a rejected promise like an unhandled exception', function() {
var promise = new StubPromise(),
const promise = new StubPromise(),
queueableFn1 = {
fn: function() {
setTimeout(function() {
@@ -608,7 +608,7 @@ describe('QueueRunner', function() {
});
it('issues an error if the function also takes a parameter', function() {
var queueableFn = {
const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
return new StubPromise();
@@ -633,7 +633,7 @@ describe('QueueRunner', function() {
it('issues a more specific error if the function is `async`', function() {
eval('var fn = async function(done){};');
var onException = jasmine.createSpy('onException'),
const onException = jasmine.createSpy('onException'),
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [{ fn: fn }],
onException: onException
@@ -651,7 +651,7 @@ describe('QueueRunner', function() {
});
it('passes the error instance to exception handlers in HTML browsers', function() {
var error = new Error('fake error'),
const error = new Error('fake error'),
onExceptionCallback = jasmine.createSpy('on exception callback'),
queueRunner = new jasmineUnderTest.QueueRunner({
onException: onExceptionCallback
@@ -664,7 +664,7 @@ describe('QueueRunner', function() {
});
it('passes the first argument to exception handlers for compatibility', function() {
var error = new Error('fake error'),
const error = new Error('fake error'),
onExceptionCallback = jasmine.createSpy('on exception callback'),
queueRunner = new jasmineUnderTest.QueueRunner({
onException: onExceptionCallback
@@ -677,7 +677,7 @@ describe('QueueRunner', function() {
});
it('calls exception handlers when an exception is thrown in a fn', function() {
var queueableFn = {
const queueableFn = {
type: 'queueable',
fn: function() {
throw new Error('fake error');
@@ -695,7 +695,7 @@ describe('QueueRunner', function() {
});
it('continues running the functions even after an exception is thrown in an async spec', function() {
var queueableFn = {
const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
throw new Error('error');
@@ -773,7 +773,7 @@ describe('QueueRunner', function() {
describe('When configured to complete on first error', function() {
it('skips to cleanup functions on the first exception', function() {
var queueableFn = {
const queueableFn = {
fn: function() {
throw new Error('error');
}
@@ -799,7 +799,7 @@ describe('QueueRunner', function() {
});
it('does not skip when a cleanup function throws', function() {
var queueableFn = { fn: function() {} },
const queueableFn = { fn: function() {} },
cleanupFn1 = {
fn: function() {
throw new Error('error');
@@ -829,27 +829,30 @@ describe('QueueRunner', function() {
});
it('skips to cleanup functions once the fn completes after an unhandled exception', function() {
var errorListeners = [],
queueableFn = {
fn: function(done) {
queueableFnDone = done;
const errorListeners = [];
let queueableFnDone;
const queueableFn = {
fn: function(done) {
queueableFnDone = done;
}
};
const nextQueueableFn = { fn: jasmine.createSpy('nextFunction') };
const cleanupFn = {
fn: jasmine.createSpy('cleanup'),
type: 'specCleanup'
};
const queueRunner = new jasmineUnderTest.QueueRunner({
globalErrors: {
pushListener: function(f) {
errorListeners.push(f);
},
popListener: function() {
errorListeners.pop();
}
},
nextQueueableFn = { fn: jasmine.createSpy('nextFunction') },
cleanupFn = { fn: jasmine.createSpy('cleanup'), type: 'specCleanup' },
queueRunner = new jasmineUnderTest.QueueRunner({
globalErrors: {
pushListener: function(f) {
errorListeners.push(f);
},
popListener: function() {
errorListeners.pop();
}
},
queueableFns: [queueableFn, nextQueueableFn, cleanupFn],
SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy
}),
queueableFnDone;
queueableFns: [queueableFn, nextQueueableFn, cleanupFn],
SkipPolicy: jasmineUnderTest.CompleteOnFirstErrorSkipPolicy
});
queueRunner.execute();
errorListeners[errorListeners.length - 1](new Error('error'));
@@ -860,7 +863,7 @@ describe('QueueRunner', function() {
});
it('skips to cleanup functions when next.fail is called', function() {
var queueableFn = {
const queueableFn = {
fn: function(done) {
done.fail('nope');
}
@@ -879,7 +882,7 @@ describe('QueueRunner', function() {
});
it('skips to cleanup functions when next is called with an Error', function() {
var queueableFn = {
const queueableFn = {
fn: function(done) {
done(new Error('nope'));
}
@@ -903,7 +906,7 @@ describe('QueueRunner', function() {
});
it('calls a provided complete callback when done', function() {
var queueableFn = { fn: jasmine.createSpy('fn') },
const queueableFn = { fn: jasmine.createSpy('fn') },
completeCallback = jasmine.createSpy('completeCallback'),
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn],
@@ -925,7 +928,7 @@ describe('QueueRunner', function() {
});
it('calls a provided stack clearing function when done', function() {
var asyncFn = {
const asyncFn = {
fn: function(done) {
done();
}
@@ -954,16 +957,16 @@ describe('QueueRunner', function() {
describe('when user context has not been defined', function() {
beforeEach(function() {
var fn;
const fn = jasmine.createSpy('fn1');
this.fn = fn = jasmine.createSpy('fn1');
this.fn = fn;
this.queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [{ fn: fn }]
});
});
it('runs the functions on the scope of a UserContext', function() {
var context;
let context;
this.fn.and.callFake(function() {
context = this;
});
@@ -976,9 +979,10 @@ describe('QueueRunner', function() {
describe('when user context has been defined', function() {
beforeEach(function() {
var fn, context;
const fn = jasmine.createSpy('fn1');
let context;
this.fn = fn = jasmine.createSpy('fn1');
this.fn = fn;
this.context = context = new jasmineUnderTest.UserContext();
this.queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [{ fn: fn }],
@@ -987,7 +991,7 @@ describe('QueueRunner', function() {
});
it('runs the functions on the scope of a UserContext', function() {
var context;
let context;
this.fn.and.callFake(function() {
context = this;
});