From 5553ced20284f1755739432a2bd52ff436ce83fc Mon Sep 17 00:00:00 2001 From: uki00a Date: Sun, 8 Dec 2024 22:44:08 +0900 Subject: [PATCH] feat: improve type-safety for events --- tests/commands/connection.ts | 38 +++++++++++++++++------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/tests/commands/connection.ts b/tests/commands/connection.ts index 87749fba..bcc30488 100644 --- a/tests/commands/connection.ts +++ b/tests/commands/connection.ts @@ -136,43 +136,39 @@ export function connectionTests( let closeEventFired = false, endEventFired = false; + const firedEvents: Array = []; client.addEventListener("close", () => { closeEventFired = true; + firedEvents.push("close"); }); client.addEventListener("end", () => { endEventFired = true; + firedEvents.push("end"); }); client.close(); assertEquals(closeEventFired, true); assertEquals(endEventFired, true); + assertEquals(firedEvents, ["close", "end"]); }); it("fires events with a lazy client", async () => { const client = createLazyClient(getOpts()); - - let connectEventFired = false, - connectEventFiredTimes = 0, - readyEventFired = false, - readyEventFiredTimes = 0, - closeEventFired = false, - endEventFired = false; + const firedEvents: Array = []; client.addEventListener("connect", () => { - connectEventFired = true; - connectEventFiredTimes++; + firedEvents.push("connect"); }); client.addEventListener("ready", () => { - readyEventFired = true; - readyEventFiredTimes++; + firedEvents.push("ready"); }, { once: true }); client.addEventListener("close", () => { - closeEventFired = true; + firedEvents.push("close"); }); client.addEventListener("end", () => { - endEventFired = true; + firedEvents.push("end"); }); await client.exists("foo"); @@ -182,13 +178,15 @@ export function connectionTests( await client.exists("foo"); client.close(); - assertEquals(connectEventFired, true); - assertEquals(readyEventFired, true); - assertEquals(closeEventFired, true); - assertEquals(endEventFired, true); - - assertEquals(connectEventFiredTimes, 2); - assertEquals(readyEventFiredTimes, 1); + assertEquals(firedEvents, [ + "connect", + "ready", + "close", + "end", + "connect", + "close", + "end", + ]); }); });