Skip to content

Commit

Permalink
test: wrap nextDate(s) test in a describe block
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed Aug 15, 2023
1 parent a0cff94 commit dfb89ae
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions tests/cron.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,42 +963,44 @@ describe('cron', () => {
});
});

it('should give the next date to run at', () => {
const callback = jest.fn();
const clock = sinon.useFakeTimers();
const job = new cron.CronJob('* * * * * *', callback);
const d = Date.now();
describe('nextDate(s)', () => {
it('should give the next date to run at', () => {
const callback = jest.fn();
const clock = sinon.useFakeTimers();
const job = new cron.CronJob('* * * * * *', callback);
const d = Date.now();

expect(job.nextDate().toMillis()).toEqual(d + 1000);
expect(job.nextDate().toMillis()).toEqual(d + 1000);

clock.restore();
});
clock.restore();
});

it('should give the next dates to run at', () => {
const callback = jest.fn();
const clock = sinon.useFakeTimers();
const job = new cron.CronJob('* * * * * *', callback);
const d = Date.now();
it('should give the next 5 dates to run at', () => {
const callback = jest.fn();
const clock = sinon.useFakeTimers();
const job = new cron.CronJob('* * * * * *', callback);
const d = Date.now();

expect(job.nextDates(5).map(d => d.toMillis())).toEqual([
d + 1000,
d + 2000,
d + 3000,
d + 4000,
d + 5000
]);
expect(job.nextDates(5).map(d => d.toMillis())).toEqual([
d + 1000,
d + 2000,
d + 3000,
d + 4000,
d + 5000
]);

clock.restore();
});
clock.restore();
});

it('Should give an empty array', () => {
const callback = jest.fn();
const clock = sinon.useFakeTimers();
const job = new cron.CronJob('* * * * * *', callback);
it('should give an empty array when called without argument', () => {
const callback = jest.fn();
const clock = sinon.useFakeTimers();
const job = new cron.CronJob('* * * * * *', callback);

expect(job.nextDates()).toHaveLength(0);
expect(job.nextDates()).toHaveLength(0);

clock.restore();
clock.restore();
});
});

it('should automatically setup a new timeout if we roll past the max timeout delay', () => {
Expand Down

0 comments on commit dfb89ae

Please sign in to comment.