diff --git a/packages/stdlib/src/patterns/behavioral/pubsub/index.test.ts b/packages/stdlib/src/patterns/behavioral/pubsub/index.test.ts index 54ab8fa..b91eb5e 100644 --- a/packages/stdlib/src/patterns/behavioral/pubsub/index.test.ts +++ b/packages/stdlib/src/patterns/behavioral/pubsub/index.test.ts @@ -2,9 +2,12 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; import { PubSub } from './index'; describe('pubsub', () => { + const event3 = Symbol('event3'); + let eventBus: PubSub<{ event1: (arg: string) => void; - event2: () => void + event2: () => void; + [event3]: () => void; }>; beforeEach(() => { @@ -32,6 +35,15 @@ describe('pubsub', () => { expect(listener2).toHaveBeenCalledWith('Hello'); }); + it('emit symbol event', () => { + const listener = vi.fn(); + + eventBus.on(event3, listener); + eventBus.emit(event3); + + expect(listener).toHaveBeenCalled(); + }); + it('add a one-time listener and emit an event', () => { const listener = vi.fn(); diff --git a/packages/stdlib/src/patterns/behavioral/pubsub/index.ts b/packages/stdlib/src/patterns/behavioral/pubsub/index.ts index 8e31a3a..c5ef436 100644 --- a/packages/stdlib/src/patterns/behavioral/pubsub/index.ts +++ b/packages/stdlib/src/patterns/behavioral/pubsub/index.ts @@ -1,5 +1,5 @@ export type Subscriber = (...args: any[]) => void; -export type EventsRecord = Record; +export type EventsRecord = Record; /** * Simple PubSub implementation