mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
throw error if missing callback in event bus
This commit is contained in:
@@ -35,6 +35,9 @@ export class EventBus {
|
|||||||
* listener.
|
* listener.
|
||||||
*/
|
*/
|
||||||
on(eventType: string, owner: any, callback: Callback) {
|
on(eventType: string, owner: any, callback: Callback) {
|
||||||
|
if (!callback) {
|
||||||
|
throw new Error("Missing callback");
|
||||||
|
}
|
||||||
if (!this.subscriptions[eventType]) {
|
if (!this.subscriptions[eventType]) {
|
||||||
this.subscriptions[eventType] = [];
|
this.subscriptions[eventType] = [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ describe("event bus behaviour", () => {
|
|||||||
bus.trigger("event");
|
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", () => {
|
test("can unsubscribe", () => {
|
||||||
const bus = new EventBus();
|
const bus = new EventBus();
|
||||||
let notified = false;
|
let notified = false;
|
||||||
Reference in New Issue
Block a user