Skip to content

Commit

Permalink
test(): add test for error handling in request scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
pooreumu committed Aug 6, 2023
1 parent fcacc9e commit 498fbb3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions tests/e2e/module-e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,26 @@ describe('EventEmitterModule - e2e', () => {
expect(customConsumer.isEmitted).toBeTruthy();
});

it('should be able to gracefully recover when an unexpected error occurs', async () => {
it('should be able to gracefully recover when an unexpected error occurs from provider', async () => {
const eventsConsumerRef = app.get(EventsProviderConsumer);
await app.init();

const emitter = app.get(EventEmitter2);
const result = emitter.emit('error-handling.event');
const result = emitter.emit('error-handling.provider');

expect(eventsConsumerRef.errorHandlingCalls).toEqual(1);
expect(result).toBeTruthy();
});

it('should be able to gracefully recover when an unexpected error occurs from request scoped', async () => {
await app.init();

const eventEmitter = app.get(EventEmitter2);
const result = eventEmitter.emit('error-handling.request-scoped');

expect(result).toBeTruthy();
});

afterEach(async () => {
await app.close();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/src/events-provider.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class EventsProviderConsumer {
this.stackedEventCalls++;
}

@OnEvent('error-handling.*')
@OnEvent('error-handling.provider')
onErrorHandlingEvent() {
this.errorHandlingCalls++;
throw new Error('This is a test error');
Expand Down
5 changes: 5 additions & 0 deletions tests/src/events-provider.request-scoped.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ export class EventsProviderRequestScopedConsumer {

@OnEvent('string.*')
onStringPayloadEvent() {}

@OnEvent('error-handling.request-scoped')
onErrorHandlingEvent() {
throw new Error('This is a test error');
}
}

0 comments on commit 498fbb3

Please # to comment.