diff --git a/src/service/amqp/amqp.service.spec.ts b/src/service/amqp/amqp.service.spec.ts index 8e39d86..cc8704e 100644 --- a/src/service/amqp/amqp.service.spec.ts +++ b/src/service/amqp/amqp.service.spec.ts @@ -49,6 +49,9 @@ describe('AMQPService', () => { }, linkOptions: options, })), + _connection: { + dispatch: () => {}, + }, })); }); @@ -162,7 +165,16 @@ describe('AMQPService', () => { await AMQPService.createConnection({ connectionUri: connectionSecureUri }); - connectionEvents.forEach(event => event.callback({ error: new Error('test') })); + connectionEvents.forEach(event => + event.callback( + new EventContextMock({ + error: new Error('test'), + connection: { + open: () => Promise.resolve({}), + }, + }), + ), + ); expect(connectionEvents.length).toBeGreaterThan(0); }); diff --git a/src/service/amqp/amqp.service.ts b/src/service/amqp/amqp.service.ts index 4dff019..7572ee2 100644 --- a/src/service/amqp/amqp.service.ts +++ b/src/service/amqp/amqp.service.ts @@ -92,7 +92,7 @@ export class AMQPService { logger.error(`connection closed with error: ${context.error.name} - ${context.error.message}`, context.error.stack); const timeoutHandler = setTimeout(async () => { - context.connection.emit(ConnectionEvents.disconnected); + (context.connection as any)._connection.dispatch(ConnectionEvents.disconnected, void 0); await context.connection .open() .then(() => { diff --git a/src/test/event-context.mock.ts b/src/test/event-context.mock.ts index bfe6ba6..ccbc17c 100644 --- a/src/test/event-context.mock.ts +++ b/src/test/event-context.mock.ts @@ -11,6 +11,9 @@ export class EventContextMock implements EventContext { public connection: any = { emit: jest.fn(), open: jest.fn(), + _connection: { + dispatch: () => {}, + }, }; public container: any = jest.fn(); public _context: any = jest.fn();