The old style of merging all of a function's variable declarations into a single statement made some sense back in the days of var, but there's no reason to keep doing it now that we use const and let.
34 lines
933 B
JavaScript
34 lines
933 B
JavaScript
describe('Timer', function() {
|
|
it('reports the time elapsed', function() {
|
|
const fakeNow = jasmine.createSpy('fake Date.now');
|
|
const timer = new jasmineUnderTest.Timer({ now: fakeNow });
|
|
|
|
fakeNow.and.returnValue(100);
|
|
timer.start();
|
|
|
|
fakeNow.and.returnValue(200);
|
|
|
|
expect(timer.elapsed()).toEqual(100);
|
|
});
|
|
|
|
describe('when date is stubbed, perhaps by other testing helpers', function() {
|
|
const origDate = Date;
|
|
beforeEach(function() {
|
|
// eslint-disable-next-line no-implicit-globals
|
|
Date = jasmine.createSpy('date spy');
|
|
});
|
|
|
|
afterEach(function() {
|
|
// eslint-disable-next-line no-implicit-globals
|
|
Date = origDate;
|
|
});
|
|
|
|
it('does not throw even though Date was taken away', function() {
|
|
const timer = new jasmineUnderTest.Timer();
|
|
|
|
expect(timer.start).not.toThrow();
|
|
expect(timer.elapsed()).toEqual(jasmine.any(Number));
|
|
});
|
|
});
|
|
});
|