I am trying to write tests in NestJS with Jest. But when I import the module, I get this error. note that
- at index 6 the service expects paramX.
- param X is part of module X
- this module X is imported in current Module (module that i am testing) as forwardRef(() => moduleX) and vice versa
can anyone suggest a workaround for this issue?
Test Module Code:
imports: [
TestingModule,
moduleA,
WinstonModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => configService.getWinstonOptions(),
}),
]
})
.overrideGuard(AuthGuard('jwt'))
.useValue(mockJWTGuard)
.overrideProvider('REQUEST')
.useValue({
ip: '127.0.0.1',
headers: {
'x-original-forwarded-for': '127.0.0.1',
},
user: {
id: 1,
},
})
Error
Nest can't resolve dependencies of the serviceA (param1, param2, param3, param4, param5, param6, ?, param8, param9, param9, param10, param11, REQUEST). Please make sure that the argument dependency at index [6] is available in the RootTestModule context.
Potential solutions:
- If dependency is a provider, is it part of the current RootTestModule?
- If dependency is exported from a separate @Module, is that module imported within RootTestModule?
@Module({
imports: [ /* the Module containing dependency */ ]
})