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,18 +1,18 @@
describe('SpyStrategy', function() {
it('defaults its name to unknown', function() {
var spyStrategy = new jasmineUnderTest.SpyStrategy();
const spyStrategy = new jasmineUnderTest.SpyStrategy();
expect(spyStrategy.identity).toEqual('unknown');
});
it('takes a name', function() {
var spyStrategy = new jasmineUnderTest.SpyStrategy({ name: 'foo' });
const spyStrategy = new jasmineUnderTest.SpyStrategy({ name: 'foo' });
expect(spyStrategy.identity).toEqual('foo');
});
it('stubs an original function, if provided', function() {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.exec();
@@ -21,12 +21,11 @@ describe('SpyStrategy', function() {
});
it("allows an original function to be called, passed through the params and returns it's value", function() {
var originalFn = jasmine.createSpy('original').and.returnValue(42),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
returnValue;
const originalFn = jasmine.createSpy('original').and.returnValue(42),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.callThrough();
returnValue = spyStrategy.exec(null, ['foo']);
const returnValue = spyStrategy.exec(null, ['foo']);
expect(originalFn).toHaveBeenCalled();
expect(originalFn.calls.mostRecent().args).toEqual(['foo']);
@@ -34,19 +33,18 @@ describe('SpyStrategy', function() {
});
it('can return a specified value when executed', function() {
var originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
returnValue;
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.returnValue(17);
returnValue = spyStrategy.exec();
const returnValue = spyStrategy.exec();
expect(originalFn).not.toHaveBeenCalled();
expect(returnValue).toEqual(17);
});
it('can return specified values in order specified when executed', function() {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.returnValues('value1', 'value2', 'value3');
@@ -59,7 +57,7 @@ describe('SpyStrategy', function() {
});
it('allows an exception to be thrown when executed', function() {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.throwError(new TypeError('bar'));
@@ -71,7 +69,7 @@ describe('SpyStrategy', function() {
});
it('allows a string to be thrown, wrapping it into an exception when executed', function() {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.throwError('bar');
@@ -83,7 +81,7 @@ describe('SpyStrategy', function() {
});
it('allows a non-Error to be thrown when executed', function() {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.throwError({ code: 'ESRCH' });
@@ -95,20 +93,19 @@ describe('SpyStrategy', function() {
});
it('allows a fake function to be called instead', function() {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
returnValue;
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.callFake(fakeFn);
returnValue = spyStrategy.exec();
const returnValue = spyStrategy.exec();
expect(originalFn).not.toHaveBeenCalled();
expect(returnValue).toEqual(67);
});
it('allows a fake async function to be called instead', function(done) {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
fakeFn = jasmine
.createSpy('fake')
.and.callFake(eval('async () => { return 67; }')),
@@ -130,7 +127,7 @@ describe('SpyStrategy', function() {
describe('#resolveTo', function() {
it('allows a resolved promise to be returned', function(done) {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
fn: originalFn
});
@@ -146,7 +143,7 @@ describe('SpyStrategy', function() {
});
it('allows an empty resolved promise to be returned', function(done) {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
fn: originalFn
});
@@ -164,7 +161,7 @@ describe('SpyStrategy', function() {
describe('#rejectWith', function() {
it('allows a rejected promise to be returned', function(done) {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
fn: originalFn
});
@@ -181,7 +178,7 @@ describe('SpyStrategy', function() {
});
it('allows an empty rejected promise to be returned', function(done) {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
fn: originalFn
});
@@ -198,7 +195,7 @@ describe('SpyStrategy', function() {
});
it('allows a non-Error to be rejected', function(done) {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
fn: originalFn
});
@@ -216,7 +213,7 @@ describe('SpyStrategy', function() {
});
it('allows a custom strategy to be used', function() {
var plan = jasmine
const plan = jasmine
.createSpy('custom strategy')
.and.returnValue('custom strategy result'),
customStrategy = jasmine
@@ -239,7 +236,7 @@ describe('SpyStrategy', function() {
});
it("throws an error if a custom strategy doesn't return a function", function() {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({
fn: originalFn,
customStrategies: {
@@ -255,7 +252,7 @@ describe('SpyStrategy', function() {
});
it('does not allow custom strategies to overwrite existing methods', function() {
var spyStrategy = new jasmineUnderTest.SpyStrategy({
const spyStrategy = new jasmineUnderTest.SpyStrategy({
fn: function() {},
customStrategies: {
exec: function() {}
@@ -266,7 +263,7 @@ describe('SpyStrategy', function() {
});
it('throws an error when a non-function is passed to callFake strategy', function() {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false);
@@ -282,7 +279,7 @@ describe('SpyStrategy', function() {
});
it('allows generator functions to be passed to callFake strategy', function() {
var generator = function*() {
const generator = function*() {
yield 'ok';
},
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: function() {} });
@@ -293,13 +290,12 @@ describe('SpyStrategy', function() {
});
it('allows a return to plan stubbing after another strategy', function() {
var originalFn = jasmine.createSpy('original'),
const originalFn = jasmine.createSpy('original'),
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn }),
returnValue;
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
spyStrategy.callFake(fakeFn);
returnValue = spyStrategy.exec();
let returnValue = spyStrategy.exec();
expect(originalFn).not.toHaveBeenCalled();
expect(returnValue).toEqual(67);
@@ -311,7 +307,7 @@ describe('SpyStrategy', function() {
});
it('returns the spy after changing the strategy', function() {
var spy = {},
const spy = {},
spyFn = jasmine.createSpy('spyFn').and.returnValue(spy),
spyStrategy = new jasmineUnderTest.SpyStrategy({ getSpy: spyFn });