I want to create a unit test for my NestJS service, which is a database repository.
I have an error: Nest can't resolve dependencies of the RescuerFunctionRepository (?). Please make sure that the argument "RescuerFunctionRepository" at index [0] is available in the RootTestModule context.
.
The code:
describe('RescuerFunctionRepository', () => {
let repository: RescuerFunctionRepository
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [RescuerFunctionRepository],
}).compile()
repository = module.get<RescuerFunctionRepository>(RescuerFunctionRepository)
})
it('should be defined', () => {
expect(repository).toBeDefined()
})
})
It happens also when I add into Test.createTestingModule()
an import statement with my module when I have registered SequelizeModule.
The structure of modules:
- AppModule imports CommonModule.
- CommonModule imports and exports DatabaseModule.
- The DatabaseModule imports SequelizeModule and registers it using
forRootAsync
. All of the repositories are registered as providers and are exported.
How can I resolve this error?