diff --git a/lib/Client.mjs b/lib/Client.mjs index 5695b1a..afa966e 100644 --- a/lib/Client.mjs +++ b/lib/Client.mjs @@ -16,6 +16,9 @@ class Client { } setBroadcast(flag, cb) { if (!cb) cb = () => {}; + if (typeof flag !== 'boolean') { + throw new TypeError('flag must be a boolean'); + } if (this._bound) { this._sock.setBroadcast(flag); cb(); diff --git a/test/test-client.mjs b/test/test-client.mjs index dba3b77..872a17a 100644 --- a/test/test-client.mjs +++ b/test/test-client.mjs @@ -111,6 +111,18 @@ test('client: setBroadcast', (t) => { }); }); +test('client: setBroadcast typeError', (t) => { + const client = new Client('127.0.0.1', t.context.port); + + t.plan(1); + + t.throws(() => { + client.setBroadcast('Oops');; + }); + + client.close(); +}); + test('client: failure', (t) => { const client = new Client('127.0.0.1', t.context.port);