Skip to content

Commit

Permalink
test(e2e): add test to verify a string payload is correctly injected …
Browse files Browse the repository at this point in the history
…in an event listener
  • Loading branch information
thiagomini committed Jul 8, 2022
1 parent 64555d0 commit afeeb0c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/e2e/module-e2e.spec.ts
Expand Up @@ -70,6 +70,14 @@ describe('EventEmitterModule - e2e', () => {
});
});

it('should be able to emit a request-scoped event with a string payload', async () => {
await app.init();

expect(
EventsProviderRequestScopedConsumer.injectedEventStringPayload,
).toEqual('some-string');
});

it('should be able to emit a request-scoped event with multiple payloads', async () => {
await app.init();

Expand Down
7 changes: 7 additions & 0 deletions tests/src/events-provider.request-scoped.consumer.ts
Expand Up @@ -8,17 +8,24 @@ export class EventsProviderRequestScopedConsumer {
if (Array.isArray(this.eventRef)) {
EventsProviderRequestScopedConsumer.injectedEventMultiPayload =
this.eventRef;
} else if (typeof this.eventRef === 'string') {
EventsProviderRequestScopedConsumer.injectedEventStringPayload =
this.eventRef;
} else {
EventsProviderRequestScopedConsumer.injectedEventPayload = this.eventRef;
}
}

public static injectedEventPayload = {};
public static injectedEventMultiPayload: any[] = [];
public static injectedEventStringPayload = '';

@OnEvent('test.*')
onTestEvent() {}

@OnEvent('multiple.*')
onMultiplePayloadEvent() {}

@OnEvent('string.*')
onStringPayloadEvent() {}
}
1 change: 1 addition & 0 deletions tests/src/events.producer.ts
Expand Up @@ -12,5 +12,6 @@ export class EventsProducer implements OnApplicationBootstrap {
{ test: 'event' },
{ test2: 'event2' },
);
this.eventEmitter.emit('string.event', 'some-string');
}
}

0 comments on commit afeeb0c

Please sign in to comment.