Skip to content

Commit 31989e0

Browse files
sheerloxintcreator
authored andcommitted
chore: wrap setTime tests in describe and move down
1 parent 8e5fc90 commit 31989e0

File tree

1 file changed

+52
-50
lines changed

1 file changed

+52
-50
lines changed

tests/cron.test.js

+52-50
Original file line numberDiff line numberDiff line change
@@ -452,56 +452,6 @@ describe('cron', () => {
452452
});
453453
});
454454

455-
it('should start, change time, start again', () => {
456-
const callback = jest.fn();
457-
const clock = sinon.useFakeTimers();
458-
459-
const job = new cron.CronJob('* * * * * *', callback);
460-
461-
job.start();
462-
clock.tick(1000);
463-
464-
job.stop();
465-
const time = cron.time('*/2 * * * * *');
466-
job.setTime(time);
467-
job.start();
468-
469-
clock.tick(4000);
470-
471-
clock.restore();
472-
job.stop();
473-
expect(callback).toHaveBeenCalledTimes(3);
474-
});
475-
476-
it('should setTime with invalid object', () => {
477-
const callback = jest.fn();
478-
const job = new cron.CronJob('* * * * * *', callback);
479-
expect(() => {
480-
job.setTime(undefined);
481-
}).toThrow();
482-
});
483-
484-
it('should start, change time, exception', () => {
485-
const callback = jest.fn();
486-
const clock = sinon.useFakeTimers();
487-
488-
const job = new cron.CronJob('* * * * * *', callback);
489-
490-
const time = new Date();
491-
job.start();
492-
493-
clock.tick(1000);
494-
495-
job.stop();
496-
expect(() => {
497-
job.setTime(time);
498-
}).toThrow();
499-
500-
clock.restore();
501-
job.stop();
502-
expect(callback).toHaveBeenCalledTimes(1);
503-
});
504-
505455
it('should scope onTick to running job', () => {
506456
const clock = sinon.useFakeTimers();
507457

@@ -894,6 +844,58 @@ describe('cron', () => {
894844
});
895845
});
896846

847+
describe('setTime', () => {
848+
it('should start, change time, start again', () => {
849+
const callback = jest.fn();
850+
const clock = sinon.useFakeTimers();
851+
852+
const job = new cron.CronJob('* * * * * *', callback);
853+
854+
job.start();
855+
clock.tick(1000);
856+
857+
job.stop();
858+
const time = cron.time('*/2 * * * * *');
859+
job.setTime(time);
860+
job.start();
861+
862+
clock.tick(4000);
863+
864+
clock.restore();
865+
job.stop();
866+
expect(callback).toHaveBeenCalledTimes(3);
867+
});
868+
869+
it('should setTime with invalid object', () => {
870+
const callback = jest.fn();
871+
const job = new cron.CronJob('* * * * * *', callback);
872+
expect(() => {
873+
job.setTime(undefined);
874+
}).toThrow();
875+
});
876+
877+
it('should start, change time, exception', () => {
878+
const callback = jest.fn();
879+
const clock = sinon.useFakeTimers();
880+
881+
const job = new cron.CronJob('* * * * * *', callback);
882+
883+
const time = new Date();
884+
job.start();
885+
886+
clock.tick(1000);
887+
888+
job.stop();
889+
expect(() => {
890+
job.setTime(time);
891+
}).toThrow();
892+
893+
clock.restore();
894+
job.stop();
895+
expect(callback).toHaveBeenCalledTimes(1);
896+
});
897+
});
898+
897899
it('should give the next date to run at', () => {
898900
const callback = jest.fn();
899901
const clock = sinon.useFakeTimers();

0 commit comments

Comments
 (0)