Skip to content

Commit

Permalink
test: verify more thoroughly when events are fired (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a authored Dec 9, 2024
1 parent 26b691b commit d9210ea
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tests/commands/connection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { createLazyClient } from "../../mod.ts";
import { assert, assertEquals, assertExists } from "../../deps/std/assert.ts";
import {
assert,
assertEquals,
assertExists,
assertInstanceOf,
} from "../../deps/std/assert.ts";
import { afterAll, beforeAll, describe, it } from "../../deps/std/testing.ts";
import { delay } from "../../deps/std/async.ts";
import type { Connector, TestServer } from "../test_util.ts";
Expand Down Expand Up @@ -161,22 +166,28 @@ export function connectionTests(
const client = createLazyClient(getOpts());
const firedEvents: Array<string> = [];

client.addEventListener("connect", () => {
client.addEventListener("connect", (e) => {
firedEvents.push("connect");
assertInstanceOf(e, CustomEvent);
});
client.addEventListener("ready", () => {
client.addEventListener("ready", (e) => {
firedEvents.push("ready");
assertInstanceOf(e, CustomEvent);
}, { once: true });

client.addEventListener("close", () => {
client.addEventListener("close", (e) => {
firedEvents.push("close");
assertInstanceOf(e, CustomEvent);
});
client.addEventListener("end", () => {
client.addEventListener("end", (e) => {
firedEvents.push("end");
assertInstanceOf(e, CustomEvent);
});

await client.exists("foo");
assertEquals(firedEvents, ["connect", "ready"]);
client.close();
assertEquals(firedEvents, ["connect", "ready", "close", "end"]);

await client.connect();
await client.exists("foo");
Expand Down

0 comments on commit d9210ea

Please sign in to comment.