Skip to content

Commit

Permalink
feat(queue-module): throw error if no way to create provider is supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
raschan committed Aug 24, 2021
1 parent 76b0cb6 commit d711d81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/queue.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ describe('QueueModule', () => {

expect(amqpService.getModuleOptions()).toEqual({ connectionUri });
});

it('should throw error when no provider is added', async () => {
try {
Test.createTestingModule({
imports: [QueueModule.forRootAsync({ imports: [TestQueueConfigModule] })],
});
expect.assertions(1);
} catch (e) {
expect(e.message).toBe('Must provide factory, class or existing provider');
}
});
});

describe('make to global module', () => {
Expand Down
7 changes: 5 additions & 2 deletions src/queue.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ export class QueueModule implements OnModuleInit, OnModuleDestroy {
};
}

// `as Type<QueueOptionsFactory>` is a workaround for microsoft/TypeScript#31603
const inject = [(options.useClass || options.useExisting) as Type<QueueModuleOptionsFactory>];
if (!options.useClass && !options.useExisting) {
throw new Error('Must provide factory, class or existing provider');
}

const inject = [options.useClass ?? options.useExisting];

return {
provide: QUEUE_MODULE_OPTIONS,
Expand Down

0 comments on commit d711d81

Please sign in to comment.