I'm quite new on nestjs, met an issue regarding how to override the load function of ConfigModule, hope someone can help me out, thanks in advance!
My e2e testing:
const moduleForTesting = await Test.createTestingModule({imports: [AppModule]});
My App Module:
import config from './config/index'
@Module({
imports: [ConfigModule.forRoot({isGlobal: true, load: [config]})]
})
My config/index file:
export default async () => {
someConfigs: ...
}
Now I want the e2e testings use another configurations, but I don't know how to override the AppModule, nor the load function:
// AppModule
import config from './config/index' // This is ok for production, but need to be overridden in testing
...
imports: [ConfigModule.forRoot({isGlobal: true, load: [config]})]
I don't know what is the elegant NestJs way to do that, but after a deep breath, I reconsidered what I really want to do and then found a hackie way to achieve that.
I need to mock the
configfile so that during testing, theloadarray will be mocked, where thejest.mockcomes to the rescue: