Skip to content

Commit

Permalink
test(std/watch): add tests for closing streams
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Mar 22, 2024
1 parent 8fc4919 commit b8e3af6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions std/watch_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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);
});
});

0 comments on commit b8e3af6

Please sign in to comment.