Skip to content

Commit

Permalink
Add test for SubscribingEventEmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Apr 6, 2020
1 parent 70a9b30 commit 62604eb
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions __tests__/core/SubscribingEventEmitter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { SubscribingEventEmitter } from "../../src/utils/SubscribingEventEmitter";

class Worker extends SubscribingEventEmitter {}

class Subscriber {
/**
* counter for invocations
*/
public events = {
function: 0,
};

getSubscribedEvents() {
return {
function: () => this.events["function"]++,
};
}
}

describe("utils", () => {
describe("SubscribingEventEmitter", () => {
test("register/unregister listeners", async () => {
const worker = new Worker();
expect(worker.listenerCount("function")).toBe(0);

worker.addSubscriber(new Subscriber());
expect(worker.listenerCount("function")).toBe(1);

worker.removeAllListeners();
expect(worker.listenerCount("function")).toBe(0);
});

test("listerner is called", async () => {
const worker = new Worker();
const subscriber = new Subscriber();
worker.addSubscriber(subscriber);
worker.emit("function");

expect(subscriber.events["function"]).toBe(1);
});
});
});

0 comments on commit 62604eb

Please sign in to comment.