Use const/let in specs, not var
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
describe('Clock', function() {
|
||||
var NODE_JS =
|
||||
const NODE_JS =
|
||||
typeof process !== 'undefined' &&
|
||||
process.versions &&
|
||||
typeof process.versions.node === 'string';
|
||||
|
||||
it('does not replace setTimeout until it is installed', function() {
|
||||
var fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
const fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
fakeGlobal = { setTimeout: fakeSetTimeout },
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
@@ -40,7 +40,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('does not replace clearTimeout until it is installed', function() {
|
||||
var fakeClearTimeout = jasmine.createSpy('global cleartimeout'),
|
||||
const fakeClearTimeout = jasmine.createSpy('global cleartimeout'),
|
||||
fakeGlobal = { clearTimeout: fakeClearTimeout },
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
@@ -76,7 +76,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('does not replace setInterval until it is installed', function() {
|
||||
var fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||
const fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||
fakeGlobal = { setInterval: fakeSetInterval },
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
@@ -111,7 +111,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('does not replace clearInterval until it is installed', function() {
|
||||
var fakeClearInterval = jasmine.createSpy('global clearinterval'),
|
||||
const fakeClearInterval = jasmine.createSpy('global clearinterval'),
|
||||
fakeGlobal = { clearInterval: fakeClearInterval },
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
@@ -147,7 +147,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('does not install if the current setTimeout is not the original function on the global', function() {
|
||||
var originalFakeSetTimeout = function() {},
|
||||
const originalFakeSetTimeout = function() {},
|
||||
replacedSetTimeout = function() {},
|
||||
fakeGlobal = { setTimeout: originalFakeSetTimeout },
|
||||
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
||||
@@ -171,7 +171,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('does not install if the current clearTimeout is not the original function on the global', function() {
|
||||
var originalFakeClearTimeout = function() {},
|
||||
const originalFakeClearTimeout = function() {},
|
||||
replacedClearTimeout = function() {},
|
||||
fakeGlobal = { clearTimeout: originalFakeClearTimeout },
|
||||
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
||||
@@ -195,7 +195,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('does not install if the current setInterval is not the original function on the global', function() {
|
||||
var originalFakeSetInterval = function() {},
|
||||
const originalFakeSetInterval = function() {},
|
||||
replacedSetInterval = function() {},
|
||||
fakeGlobal = { setInterval: originalFakeSetInterval },
|
||||
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
||||
@@ -219,7 +219,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('does not install if the current clearInterval is not the original function on the global', function() {
|
||||
var originalFakeClearInterval = function() {},
|
||||
const originalFakeClearInterval = function() {},
|
||||
replacedClearInterval = function() {},
|
||||
fakeGlobal = { clearInterval: originalFakeClearInterval },
|
||||
delayedFunctionSchedulerFactory = jasmine.createSpy(
|
||||
@@ -243,7 +243,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('replaces the global timer functions on uninstall', function() {
|
||||
var fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
const fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
||||
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
||||
@@ -286,7 +286,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('can be installed for the duration of a passed in function and uninstalled when done', function() {
|
||||
var fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
const fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
||||
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
||||
@@ -312,8 +312,8 @@ describe('Clock', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
passedFunctionCalled = false;
|
||||
);
|
||||
let passedFunctionCalled = false;
|
||||
|
||||
clock.withMock(function() {
|
||||
fakeGlobal.setTimeout(delayedFn, 0);
|
||||
@@ -346,7 +346,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('can be installed for the duration of a passed in function and uninstalled if an error is thrown', function() {
|
||||
var fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
const fakeSetTimeout = jasmine.createSpy('global setTimeout'),
|
||||
fakeClearTimeout = jasmine.createSpy('global clearTimeout'),
|
||||
fakeSetInterval = jasmine.createSpy('global setInterval'),
|
||||
fakeClearInterval = jasmine.createSpy('global clearInterval'),
|
||||
@@ -372,8 +372,8 @@ describe('Clock', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
passedFunctionCalled = false;
|
||||
);
|
||||
let passedFunctionCalled = false;
|
||||
|
||||
expect(function() {
|
||||
clock.withMock(function() {
|
||||
@@ -409,7 +409,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('schedules the delayed function (via setTimeout) with the fake timer', function() {
|
||||
var fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
||||
const fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
||||
scheduleFunction = jasmine.createSpy('scheduleFunction'),
|
||||
delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
|
||||
fakeGlobal = { setTimeout: fakeSetTimeout },
|
||||
@@ -451,7 +451,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('returns an id for the delayed function', function() {
|
||||
var fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
||||
const fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
||||
scheduleId = 123,
|
||||
scheduleFunction = jasmine
|
||||
.createSpy('scheduleFunction')
|
||||
@@ -470,11 +470,10 @@ describe('Clock', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
timeout;
|
||||
);
|
||||
|
||||
clock.install();
|
||||
timeout = clock.setTimeout(delayedFn, 0);
|
||||
const timeout = clock.setTimeout(delayedFn, 0);
|
||||
|
||||
if (!NODE_JS) {
|
||||
expect(timeout).toEqual(123);
|
||||
@@ -484,7 +483,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('clears the scheduled function with the scheduler', function() {
|
||||
var fakeClearTimeout = jasmine.createSpy('clearTimeout'),
|
||||
const fakeClearTimeout = jasmine.createSpy('clearTimeout'),
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
['removeFunctionWithId']
|
||||
@@ -513,7 +512,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('schedules the delayed function with the fake timer', function() {
|
||||
var fakeSetInterval = jasmine.createSpy('setInterval'),
|
||||
const fakeSetInterval = jasmine.createSpy('setInterval'),
|
||||
scheduleFunction = jasmine.createSpy('scheduleFunction'),
|
||||
delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
|
||||
fakeGlobal = { setInterval: fakeSetInterval },
|
||||
@@ -556,7 +555,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('returns an id for the delayed function', function() {
|
||||
var fakeSetInterval = jasmine.createSpy('setInterval'),
|
||||
const fakeSetInterval = jasmine.createSpy('setInterval'),
|
||||
scheduleId = 123,
|
||||
scheduleFunction = jasmine
|
||||
.createSpy('scheduleFunction')
|
||||
@@ -575,11 +574,10 @@ describe('Clock', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
interval;
|
||||
);
|
||||
|
||||
clock.install();
|
||||
interval = clock.setInterval(delayedFn, 0);
|
||||
const interval = clock.setInterval(delayedFn, 0);
|
||||
|
||||
if (!NODE_JS) {
|
||||
expect(interval).toEqual(123);
|
||||
@@ -589,7 +587,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('clears the scheduled function with the scheduler', function() {
|
||||
var clearInterval = jasmine.createSpy('clearInterval'),
|
||||
const clearInterval = jasmine.createSpy('clearInterval'),
|
||||
delayedFunctionScheduler = jasmine.createSpyObj(
|
||||
'delayedFunctionScheduler',
|
||||
['removeFunctionWithId']
|
||||
@@ -618,7 +616,7 @@ describe('Clock', function() {
|
||||
});
|
||||
|
||||
it('gives you a friendly reminder if the Clock is not installed and you tick', function() {
|
||||
var clock = new jasmineUnderTest.Clock(
|
||||
const clock = new jasmineUnderTest.Clock(
|
||||
{},
|
||||
jasmine.createSpyObj('delayedFunctionScheduler', ['tick'])
|
||||
);
|
||||
@@ -630,7 +628,7 @@ describe('Clock', function() {
|
||||
|
||||
describe('Clock (acceptance)', function() {
|
||||
it('can run setTimeouts/setIntervals synchronously', function() {
|
||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||
delayedFn3 = jasmine.createSpy('delayedFn3'),
|
||||
recurring1 = jasmine.createSpy('recurring1'),
|
||||
@@ -651,7 +649,7 @@ describe('Clock (acceptance)', function() {
|
||||
clock.install();
|
||||
|
||||
clock.setTimeout(delayedFn1, 0);
|
||||
var intervalId = clock.setInterval(recurring1, 50);
|
||||
const intervalId = clock.setInterval(recurring1, 50);
|
||||
clock.setTimeout(delayedFn2, 100);
|
||||
clock.setTimeout(delayedFn3, 200);
|
||||
|
||||
@@ -690,7 +688,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('can clear a previously set timeout', function() {
|
||||
var clearedFn = jasmine.createSpy('clearedFn'),
|
||||
const clearedFn = jasmine.createSpy('clearedFn'),
|
||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
mockDate = {
|
||||
install: function() {},
|
||||
@@ -703,12 +701,11 @@ describe('Clock (acceptance)', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
timeoutId;
|
||||
);
|
||||
|
||||
clock.install();
|
||||
|
||||
timeoutId = clock.setTimeout(clearedFn, 100);
|
||||
const timeoutId = clock.setTimeout(clearedFn, 100);
|
||||
expect(clearedFn).not.toHaveBeenCalled();
|
||||
|
||||
clock.clearTimeout(timeoutId);
|
||||
@@ -718,7 +715,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it("can clear a previously set interval using that interval's handler", function() {
|
||||
var spy = jasmine.createSpy('spy'),
|
||||
const spy = jasmine.createSpy('spy'),
|
||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
mockDate = {
|
||||
install: function() {},
|
||||
@@ -731,12 +728,11 @@ describe('Clock (acceptance)', function() {
|
||||
return delayedFunctionScheduler;
|
||||
},
|
||||
mockDate
|
||||
),
|
||||
intervalId;
|
||||
);
|
||||
|
||||
clock.install();
|
||||
|
||||
intervalId = clock.setInterval(function() {
|
||||
const intervalId = clock.setInterval(function() {
|
||||
spy();
|
||||
clock.clearInterval(intervalId);
|
||||
}, 100);
|
||||
@@ -746,7 +742,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('correctly schedules functions after the Clock has advanced', function() {
|
||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
mockDate = {
|
||||
install: function() {},
|
||||
@@ -772,7 +768,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('correctly schedules functions while the Clock is advancing', function() {
|
||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
mockDate = {
|
||||
@@ -803,7 +799,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('correctly calls functions scheduled while the Clock is advancing', function() {
|
||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
mockDate = {
|
||||
@@ -831,7 +827,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('correctly schedules functions scheduled while the Clock is advancing but after the Clock is uninstalled', function() {
|
||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
const delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
mockDate = {
|
||||
@@ -865,7 +861,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('does not mock the Date object by default', function() {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -880,7 +876,7 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
expect(global.Date).toEqual(Date);
|
||||
|
||||
var now = new global.Date().getTime();
|
||||
const now = new global.Date().getTime();
|
||||
|
||||
clock.tick(50);
|
||||
|
||||
@@ -888,7 +884,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('mocks the Date object and sets it to current time', function() {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -901,13 +897,13 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.install().mockDate();
|
||||
|
||||
var now = new global.Date().getTime();
|
||||
const now = new global.Date().getTime();
|
||||
|
||||
clock.tick(50);
|
||||
|
||||
expect(new global.Date().getTime() - now).toEqual(50);
|
||||
|
||||
var timeoutDate = 0;
|
||||
let timeoutDate = 0;
|
||||
clock.setTimeout(function() {
|
||||
timeoutDate = new global.Date().getTime();
|
||||
}, 100);
|
||||
@@ -918,7 +914,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('mocks the Date object and sets it to a given time', function() {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -932,7 +928,7 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.install().mockDate(baseTime);
|
||||
|
||||
var now = new global.Date().getTime();
|
||||
const now = new global.Date().getTime();
|
||||
|
||||
expect(now).toEqual(baseTime.getTime());
|
||||
|
||||
@@ -940,7 +936,7 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
expect(new global.Date().getTime()).toEqual(baseTime.getTime() + 50);
|
||||
|
||||
var timeoutDate = 0;
|
||||
let timeoutDate = 0;
|
||||
clock.setTimeout(function() {
|
||||
timeoutDate = new global.Date().getTime();
|
||||
}, 100);
|
||||
@@ -951,7 +947,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('throws mockDate is called with a non-Date', function() {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -969,7 +965,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('mocks the Date object and updates the date per delayed function', function() {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -983,8 +979,8 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.install().mockDate(baseTime);
|
||||
|
||||
var actualTimes = [];
|
||||
var pushCurrentTime = function() {
|
||||
const actualTimes = [];
|
||||
const pushCurrentTime = function() {
|
||||
actualTimes.push(global.Date().getTime());
|
||||
};
|
||||
delayedFunctionScheduler.scheduleFunction(pushCurrentTime);
|
||||
@@ -1008,7 +1004,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('correctly clears a scheduled timeout while the Clock is advancing', function() {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date, setTimeout: undefined },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -1021,7 +1017,7 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.install();
|
||||
|
||||
var timerId2;
|
||||
let timerId2;
|
||||
|
||||
global.setTimeout(function() {
|
||||
global.clearTimeout(timerId2);
|
||||
@@ -1033,7 +1029,7 @@ describe('Clock (acceptance)', function() {
|
||||
});
|
||||
|
||||
it('correctly clears a scheduled interval while the Clock is advancing', function() {
|
||||
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
const delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
||||
global = { Date: Date, setTimeout: undefined },
|
||||
mockDate = new jasmineUnderTest.MockDate(global),
|
||||
clock = new jasmineUnderTest.Clock(
|
||||
@@ -1046,7 +1042,7 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.install();
|
||||
|
||||
var timerId2;
|
||||
let timerId2;
|
||||
global.setInterval(function() {
|
||||
global.clearInterval(timerId2);
|
||||
}, 100);
|
||||
|
||||
Reference in New Issue
Block a user