Skip to content

Commit

Permalink
Add tests for class and static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Apr 6, 2020
1 parent 62604eb commit 74a7392
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions __tests__/core/SubscribingEventEmitter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,31 @@ class Subscriber {
*/
public events = {
function: 0,
start: 0,
static: 0,
};

public static staticEvents = {
static: 0,
};

onstart() {
// this this will throw if "this" is not resolved to current class
this.events["start"]++;
}

static staticMethod() {
Subscriber.staticEvents["static"]++;
}

getSubscribedEvents() {
return {
// inline callback
function: () => this.events["function"]++,
// pointer to class method
start: this.onstart,
// using static method
static: Subscriber.staticMethod,
};
}
}
Expand All @@ -34,9 +54,13 @@ describe("utils", () => {
const worker = new Worker();
const subscriber = new Subscriber();
worker.addSubscriber(subscriber);
worker.emit("start");
worker.emit("function");
worker.emit("static");

expect(subscriber.events["start"]).toBe(1);
expect(subscriber.events["function"]).toBe(1);
expect(Subscriber.staticEvents["static"]).toBe(1);
});
});
});

0 comments on commit 74a7392

Please sign in to comment.