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;
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!
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;
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;
Please let me know what you think, and if you'd be interested in a PR. Cheers!