import { EventHandlers } from '@/models/eventHandlers'; describe('eventHandlers tests', () => { it('should add the same key and handler only once', async () => { const handlers = new EventHandlers(); const fn = vi.fn(); handlers.add('fn', fn); handlers.add('fn', fn); await handlers.call('fn'); expect(fn).toHaveBeenCalledOnce(); }); it('should add different handlers', async () => { const handlers = new EventHandlers(); const a = vi.fn(); const b = vi.fn(); handlers.add('fn', a); handlers.add('fn', b); await handlers.call('fn'); expect(a).toHaveBeenCalledOnce(); expect(b).toHaveBeenCalledOnce(); }); it('should add/remove the same key and handler', () => { const handlers = new EventHandlers(); const fn = vi.fn(); handlers.add('fn', fn); expect(handlers.remove('fn', fn)).toBeTruthy(); }); it('should not remove handler of different key', () => { const handlers = new EventHandlers(); const fn = vi.fn(); handlers.add('foo', fn); expect(handlers.remove('bar', vi.fn() as any)).toBeFalsy(); }); });