[REF] owl: reorganize src code in sub files

This commit is contained in:
Géry Debongnie
2019-07-14 22:18:00 +02:00
parent 15a3f59744
commit 5382e824b1
36 changed files with 1802 additions and 1747 deletions
+45
View File
@@ -0,0 +1,45 @@
import { EventBus } from "../../src/core/event_bus";
describe("event bus behaviour", () => {
test("can subscribe and be notified", () => {
const bus = new EventBus();
let notified = false;
bus.on("event", {}, () => (notified = true));
expect(notified).toBe(false);
bus.trigger("event");
expect(notified).toBe(true);
});
test("callbacks are called with proper 'this'", () => {
expect.assertions(1);
const bus = new EventBus();
const owner = {};
bus.on("event", owner, function(this: any) {
expect(this).toBe(owner);
});
bus.trigger("event");
});
test("throw error if callback is undefined", () => {
expect.assertions(1);
const bus = new EventBus();
expect(() => bus.on("event", {}, <any>undefined)).toThrow(`Missing callback`);
});
test("can unsubscribe", () => {
const bus = new EventBus();
let notified = false;
let owner = {};
bus.on("event", owner, () => (notified = true));
bus.off("event", owner);
bus.trigger("event");
expect(notified).toBe(false);
});
test("arguments are properly propagated", () => {
expect.assertions(1);
const bus = new EventBus();
bus.on("event", {}, (arg: any) => expect(arg).toBe("hello world"));
bus.trigger("event", "hello world");
});
});