@@ -51,6 +51,8 @@ describe('AsyncDomainEventBus', () => {
5151 } ) ;
5252
5353 describe ( 'publish / subscribe' , ( ) => {
54+ const reservedTypes = [ 'error' , 'newListener' , 'removeListener' ] as const ;
55+
5456 it ( 'invokes the subscribed handler when a matching event is published' , async ( ) => {
5557 const handler = jest . fn ( ) ;
5658 bus . subscribe < FooEvent > ( 'foo' , handler ) ;
@@ -140,6 +142,21 @@ describe('AsyncDomainEventBus', () => {
140142 expect ( barHandler ) . toHaveBeenCalledTimes ( 1 ) ;
141143 expect ( barHandler ) . toHaveBeenCalledWith ( bar ) ;
142144 } ) ;
145+
146+ it . each ( reservedTypes ) (
147+ 'refuses to publish events typed "%s", logs a single warn, and does not dispatch to handlers' ,
148+ async ( reservedType ) => {
149+ const handler = jest . fn ( ) ;
150+ bus . subscribe ( reservedType , handler ) ;
151+ // @ts -expect-error: we're testing the reserved type
152+ bus . publish ( { type : reservedType } ) ;
153+
154+ await flushAsync ( ) ;
155+
156+ expect ( handler ) . not . toHaveBeenCalled ( ) ;
157+ expect ( mockLogger . warn ) . toHaveBeenCalledTimes ( 1 ) ;
158+ }
159+ ) ;
143160 } ) ;
144161
145162 describe ( 'error isolation' , ( ) => {
0 commit comments