Skip to content

Commit fcdb3a1

Browse files
committed
🌿 Add tests of Client.reply
1 parent e44a897 commit fcdb3a1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

client_test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,40 @@ import {
66
import { buildMessage } from "./message.ts";
77
import { Client } from "./client.ts";
88

9+
Deno.test("Client.reply", async (t) => {
10+
await t.step("sends a message", () => {
11+
const receives: unknown[] = [];
12+
const session = {
13+
send: (message: unknown) => {
14+
receives.push(message);
15+
},
16+
recv: () => {
17+
throw new Error("should not be called");
18+
},
19+
};
20+
const client = new Client(session);
21+
client.reply(1, "Hello");
22+
client.reply(2, "World");
23+
assertEquals(receives, [
24+
[1, "Hello"],
25+
[2, "World"],
26+
]);
27+
});
28+
29+
await t.step("throws an error when send fails", () => {
30+
const session = {
31+
send: () => {
32+
throw new Error("send error");
33+
},
34+
recv: () => {
35+
throw new Error("should not be called");
36+
},
37+
};
38+
const client = new Client(session);
39+
assertThrows(() => client.redraw(), Error, "send error");
40+
});
41+
});
42+
943
Deno.test("Client.redraw", async (t) => {
1044
await t.step("sends a redraw command", () => {
1145
const receives: unknown[] = [];

0 commit comments

Comments
 (0)