39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { describe, test, expect, mock } from "bun:test";
|
|
import { Eventra } from "@duxcore/eventra";
|
|
|
|
// We test the globalEvents module shape and the setupEventDebugger function.
|
|
// Because other test files mock.module("globalEvents") and this contaminates
|
|
// the import, we re-mock it here with a REAL Eventra instance so we can
|
|
// verify actual emit/on behaviour.
|
|
const realEvents = new Eventra();
|
|
|
|
mock.module("../../src/modules/globalEvents", () => ({
|
|
events: realEvents,
|
|
setupEventDebugger: () => {
|
|
// Real implementation registers a catch-all — safe to call.
|
|
},
|
|
}));
|
|
|
|
import { events, setupEventDebugger } from "../../src/modules/globalEvents";
|
|
|
|
describe("globalEvents", () => {
|
|
test("events is an Eventra instance", () => {
|
|
expect(events).toBeDefined();
|
|
expect(typeof events.emit).toBe("function");
|
|
expect(typeof events.on).toBe("function");
|
|
});
|
|
|
|
test("setupEventDebugger does not throw", () => {
|
|
expect(() => setupEventDebugger()).not.toThrow();
|
|
});
|
|
|
|
test("can emit and receive events", () => {
|
|
let received = false;
|
|
events.on("api:started", () => {
|
|
received = true;
|
|
});
|
|
events.emit("api:started");
|
|
expect(received).toBe(true);
|
|
});
|
|
});
|