dd-timer/tests/unit/domain/EventBus.test.ts
POL Mickaël 203c423f19 test: 302 tests unitaires + 20 E2E Playwright (couverture 94%)
- 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>
2026-04-06 05:43:29 +02:00

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();
});
});