diff --git a/std/watch_test.ts b/std/watch_test.ts index 2b242f8..bf01542 100644 --- a/std/watch_test.ts +++ b/std/watch_test.ts @@ -41,6 +41,15 @@ describe("watch - websockets", () => { assertEquals(value.type, "message"); assertEquals(value.data, "test"); }); + + it("should remove the event listener when the stream is canceled", async () => { + const stream = watch(ws)("message"); + const reader = stream.getReader(); + reader.cancel(); + ws.dispatchEvent(new MessageEvent("message", { data: "test" })); + const { done } = await reader.read(); + assertEquals(done, true); + }); }); describe("watch - relays", () => { @@ -85,4 +94,13 @@ describe("watch - relays", () => { assertEquals(value.type, "receive"); assertEquals(value.data, ["NOTICE", "test"]); }); + + it("should remove the event listener when the stream is canceled", async () => { + const stream = watch(relay)("receive"); + const reader = stream.getReader(); + reader.cancel(); + relay.dispatch("receive", ["NOTICE", "test"]); + const { done } = await reader.read(); + assertEquals(done, true); + }); });