refactor event listener registration

unified listener creation logic under `createEventListener`, adding support for a flexible `RegisterListenerConfig`. Updated associated tests and improved error handling for unregistered events.
This commit is contained in:
dswbx
2025-01-15 17:46:41 +01:00
parent 6625c9bc48
commit 438e36f185
2 changed files with 35 additions and 28 deletions

View File

@@ -61,6 +61,9 @@ describe("EventManager", async () => {
"sync"
);
// don't allow unknown
expect(() => emgr.on("unknown", () => void 0)).toThrow();
emgr.onEvent(InformationalEvent, async (event, name) => {
call();
expect(name).toBe("informational-event");
@@ -135,14 +138,14 @@ describe("EventManager", async () => {
const call = mock(() => null);
const emgr = new EventManager({ InformationalEvent });
emgr.onEventOnce(
emgr.onEvent(
InformationalEvent,
async (event, slug) => {
expect(event).toBeInstanceOf(InformationalEvent);
expect(slug).toBe("informational-event");
call();
},
"sync"
{ mode: "sync", once: true }
);
expect(emgr.getListeners().length).toBe(1);