diff --git a/packages/testing/test.ts b/packages/testing/test.ts index e9f08b26ea2..1ddf658d6c6 100644 --- a/packages/testing/test.ts +++ b/packages/testing/test.ts @@ -1,11 +1,17 @@ import { ModuleMetadata } from '@nestjs/common/interfaces/modules/module-metadata.interface'; import { MetadataScanner } from '@nestjs/core/metadata-scanner'; -import { TestingModuleBuilder } from './testing-module.builder'; +import { + TestingModuleBuilder, + TestingModuleOptions, +} from './testing-module.builder'; export class Test { private static readonly metadataScanner = new MetadataScanner(); - public static createTestingModule(metadata: ModuleMetadata) { - return new TestingModuleBuilder(this.metadataScanner, metadata); + public static createTestingModule( + metadata: ModuleMetadata, + options?: TestingModuleOptions, + ) { + return new TestingModuleBuilder(this.metadataScanner, metadata, options); } } diff --git a/packages/testing/testing-module.builder.ts b/packages/testing/testing-module.builder.ts index 6fd4443b41a..ca5d654943e 100644 --- a/packages/testing/testing-module.builder.ts +++ b/packages/testing/testing-module.builder.ts @@ -23,12 +23,20 @@ import { TestingInjector } from './testing-injector'; import { TestingInstanceLoader } from './testing-instance-loader'; import { TestingModule } from './testing-module'; +/** + * @publicApi + */ +export type TestingModuleOptions = Pick< + NestApplicationContextOptions, + 'moduleIdGeneratorAlgorithm' +>; + /** * @publicApi */ export class TestingModuleBuilder { private readonly applicationConfig = new ApplicationConfig(); - private readonly container = new NestContainer(this.applicationConfig); + private readonly container: NestContainer; private readonly overloadsMap = new Map(); private readonly moduleOverloadsMap = new Map< ModuleDefinition, @@ -41,7 +49,9 @@ export class TestingModuleBuilder { constructor( private readonly metadataScanner: MetadataScanner, metadata: ModuleMetadata, + options?: TestingModuleOptions, ) { + this.container = new NestContainer(this.applicationConfig, options); this.module = this.createModule(metadata); }