mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] move event_bus into utils, readd 2 functions
This commit is contained in:
committed by
Aaron Bohy
parent
c1439814bf
commit
1658d15b87
@@ -0,0 +1,35 @@
|
||||
import { EventBus } from "../src/utils";
|
||||
|
||||
describe("event bus behaviour", () => {
|
||||
test("can subscribe and be notified", () => {
|
||||
const bus = new EventBus();
|
||||
let notified = false;
|
||||
bus.addEventListener("event", () => {
|
||||
notified = true;
|
||||
});
|
||||
expect(notified).toBe(false);
|
||||
bus.trigger("event");
|
||||
expect(notified).toBe(true);
|
||||
});
|
||||
|
||||
test("can unsubscribe", () => {
|
||||
const bus = new EventBus();
|
||||
let n = 0;
|
||||
let cb = () => n++;
|
||||
bus.addEventListener("event", cb);
|
||||
expect(n).toBe(0);
|
||||
bus.trigger("event");
|
||||
expect(n).toBe(1);
|
||||
bus.removeEventListener("event", cb);
|
||||
expect(n).toBe(1);
|
||||
bus.trigger("event");
|
||||
expect(n).toBe(1);
|
||||
});
|
||||
|
||||
test("arguments are properly propagated", () => {
|
||||
expect.assertions(1);
|
||||
const bus = new EventBus();
|
||||
bus.addEventListener("event", (ev: any) => expect(ev.detail).toBe("hello world"));
|
||||
bus.trigger("event", "hello world");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user