I'm building a SutModule that loads a provider to mock all outgoing requests during resilience testing. This module uses nock to disable network connections, allowing us to control network blocking through configuration.
@Module({})
export class SutModule {
static register(options: SutOptionsType): DynamicModule {
const providers: Provider[] = [];
if (options.enabled) {
nock.disableNetConnect();
providers.push(SomeMockSerivce);
}
return {
module: SutModule,
providers: providers,
exports: providers,
};
}
}```
I have successfully implemented a `register` method that can be called like this:
```typescript
SutModule.register({ enabled: true });
This approach works, but I want to use an async configuration setup to dynamically set enabled based on ConfigService. My goal is to enable this configuration style:
SutModule.registerAsync({
inject: [ConfigService],
useFactory: (configService: ConfigService) => {
return { enabled: configService.get('SYSTEM_UNDER_TEST') };
},
});
Could someone help me understand how to implement a registerAsync method in the module to achieve this? Specifically, I’m looking for guidance on handling the async registration and injecting the ConfigService. Thank you!