Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Some of the event handlers cannot be unit tested #49

@onderceylan

Description

@onderceylan

Hi again!

I'd like to cover the functionality of the error handlers of my implementation with unit tests, but some of the error handlers are not reachable. AFAIK it's not possible to test them with unit tests currently, as we can't reproduce error scenarios with the public interface of SqsConsumer.

Please see the code below for examples of unreachable code blocks;

sqsConsumer.on(SqsConsumerEvents.error, err => {
  errorHandler('error', queueType, err, logger);
});

sqsConsumer.on(SqsConsumerEvents.connectionError, err => {
  errorHandler('connection_error', queueType, err, logger);
});

sqsConsumer.on(SqsConsumerEvents.s3PayloadError, err => {
  errorHandler('s3_payload_error', queueType, err, logger);
});

Proposition for the solution

To make libraries which depend on event handlers more test friendly, the interfaces that implement EventEmitter might be either updated to publicly expose the EventEmitter instance, or make the class inherit the EventEmitter interface.

Once such a change is in place, it would be possible to trigger the events hence test the event handlers like below example;

sqsConsumer.emit(SqsConsumerEvents.error, new Error('test'));

Please let me know what you think, and if you'd be interested in a PR.
Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions