- Unit : domain (GaugeCalculator, Enclos, Dragodinde, XpTable, Race, Tier...) - Unit : application (commands, queries, CommandBus) - Fonctionnel : breeding-workflow, enclos-management, timer-workflow - Régression : gauge-tier, gauge-recharge, xp-timer, level-target, breeding - E2E Playwright + Electron : navigation, timer, recharge jauge, accouplement, persistance des données Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { EventBus } from '@domain/events/EventBus';
|
|
|
|
describe('EventBus', () => {
|
|
it('dispatches events to subscribers', () => {
|
|
const bus = new EventBus();
|
|
const handler = vi.fn();
|
|
bus.on('timer-completed', handler);
|
|
bus.emit({ type: 'timer-completed', enclosId: 1 });
|
|
expect(handler).toHaveBeenCalledWith({ type: 'timer-completed', enclosId: 1 });
|
|
});
|
|
|
|
it('ignores unsubscribed event types', () => {
|
|
const bus = new EventBus();
|
|
const handler = vi.fn();
|
|
bus.on('timer-completed', handler);
|
|
bus.emit({ type: 'accouplement-registered' });
|
|
expect(handler).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('supports multiple handlers for same event', () => {
|
|
const bus = new EventBus();
|
|
const h1 = vi.fn();
|
|
const h2 = vi.fn();
|
|
bus.on('timer-completed', h1);
|
|
bus.on('timer-completed', h2);
|
|
bus.emit({ type: 'timer-completed' });
|
|
expect(h1).toHaveBeenCalled();
|
|
expect(h2).toHaveBeenCalled();
|
|
});
|
|
|
|
it('off removes handler', () => {
|
|
const bus = new EventBus();
|
|
const handler = vi.fn();
|
|
bus.on('timer-completed', handler);
|
|
bus.off('timer-completed', handler);
|
|
bus.emit({ type: 'timer-completed' });
|
|
expect(handler).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('emit with no handlers does not throw', () => {
|
|
const bus = new EventBus();
|
|
expect(() => bus.emit({ type: 'timer-completed' })).not.toThrow();
|
|
});
|
|
});
|