@nestjs/common#ModuleMetadata TypeScript Examples

The following examples show how to use @nestjs/common#ModuleMetadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: test_utils.ts    From nestjs-angular-starter with MIT License 7 votes vote down vote up
export async function createTestModuleWithDB(
  moduleMetadata: ModuleMetadata,
): Promise<{ module: TestingModule; dbService: IDatabaseService }> {
  const module: TestingModule = await Test.createTestingModule({
    imports: moduleMetadata.imports,
    providers: [
      { provide: DatabaseService, useClass: DatabaseTestService },
      ...(moduleMetadata.providers || []),
    ],
    exports: moduleMetadata.exports,
    controllers: moduleMetadata.controllers,
  }).compile();

  const dbService = module.get<IDatabaseService>(DatabaseService);
  await dbService.connect();

  return { module, dbService };
}