From 7840ea4d8db6ed1ec303cd7f63c6d2c562392d34 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Sat, 14 Dec 2024 14:55:46 -0500 Subject: [PATCH] fixup: catch error --- lib/Client.mjs | 3 +++ test/test-client.mjs | 12 ++++++++++++ 2 files changed, 15 insertions(+) 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);