-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.ts
44 lines (39 loc) · 1.13 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { InMemoryPubSub } from "../index";
describe("InMemoryPubSub", () => {
test("subscribe", async () => {
const pubsub = new InMemoryPubSub();
const messages = (async () => {
const messages = [];
for await (const message of pubsub.subscribe("topic")) {
messages.push(message);
if (message === "c") {
break;
}
}
return messages;
})();
pubsub.publish("topic", "a");
pubsub.publish("topic", "b");
pubsub.publish("topic", "c");
await expect(messages).resolves.toEqual(["a", "b", "c"]);
});
test("unpublish", async () => {
const pubsub = new InMemoryPubSub();
const messages = (async () => {
const messages = [];
for await (const message of pubsub.subscribe("topic")) {
messages.push(message);
}
return messages;
})();
pubsub.publish("topic", "a");
pubsub.publish("topic", "b");
pubsub.publish("topic", "c");
pubsub.unpublish("topic");
await expect(messages).resolves.toEqual(["a", "b", "c"]);
});
test("close", () => {
const pubsub = new InMemoryPubSub();
pubsub.close();
});
});