diff --git a/src/lease.ts b/src/lease.ts index 313c1a4..be1e76e 100644 --- a/src/lease.ts +++ b/src/lease.ts @@ -70,7 +70,7 @@ const enum State { * const hostPrefix = 'available-hosts/'; * * function grantLease() { - * const lease = client.lease(); + * const lease = client.lease(10); // set a TTL of 10 seconds * * lease.on('lost', err => { * console.log('We lost our lease as a result of this error:', err); @@ -102,7 +102,7 @@ export class Lease extends EventEmitter { ) { super(); - if (ttl < 1) { + if (!ttl || ttl < 1) { throw new Error(`The TTL in an etcd lease must be at least 1 second. Got: ${ttl}`); } diff --git a/test/lease.test.ts b/test/lease.test.ts index e7400c5..506821c 100644 --- a/test/lease.test.ts +++ b/test/lease.test.ts @@ -28,8 +28,9 @@ describe('lease()', () => { } }); - it('throws if trying to use too short of a ttl', () => { + it('throws if trying to use too short of a ttl, or an undefined ttl', () => { expect(() => client.lease(0)).to.throw(/must be at least 1 second/); + expect(() => ( client.lease)()).to.throw(/must be at least 1 second/); }); it('reports a loss and errors if the client is invalid', async () => {