Skip to content

Commit

Permalink
add some sanity-test checks to pubsub
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Jun 9, 2019
1 parent bab9317 commit c5ccc53
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/pubsub/src/__tests__/index.ts
@@ -1,6 +1,42 @@
import { InMemoryPubSub } from "../index";

describe("pubsub", () => {
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();
Expand Down

0 comments on commit c5ccc53

Please sign in to comment.