diff --git a/src/time.ts b/src/time.ts index 17b6a0eb..2a35b38a 100644 --- a/src/time.ts +++ b/src/time.ts @@ -774,10 +774,10 @@ export class CronTime { let upper = mUpper !== undefined ? parseInt(mUpper, 10) : undefined; const wasStepDefined = mStep !== undefined; - if (mStep === '0') { + const step = parseInt(mStep ?? '1', 10); + if (step === 0) { throw new Error(`Field (${unit}) has a step of zero`); } - const step = parseInt(mStep ?? '1', 10); if (upper !== undefined && lower > upper) { throw new Error(`Field (${unit}) has an invalid range`); diff --git a/tests/crontime.test.ts b/tests/crontime.test.ts index 5954a215..3827268b 100644 --- a/tests/crontime.test.ts +++ b/tests/crontime.test.ts @@ -210,9 +210,17 @@ describe('crontime', () => { }); it('should test invalid step', () => { + expect(() => { + new CronTime('* * * 1/ *'); + }).toThrow(); + expect(() => { new CronTime('* * * 1/0 *'); }).toThrow(); + + expect(() => { + new CronTime('* * * 1/00 *'); + }).toThrow(); }); it('should test invalid range', () => {