I have a service that uses the @InjectConnection
decorator in it's constructor.
I am unable to instantiate a testingModule for this service. The following error is thrown: Nest can't resolve dependencies of the AttachmentsService (?, winston). Please make sure that the argument at index [0] is available in the TestModule context.
Service constructor:
constructor(@InjectConnection() private readonly mongooseConnection: Mongoose,
@Inject(Modules.Logger) private readonly logger: Logger) {
this.attachmentGridFsRepository = gridfs({
collection: 'attachments',
model: Schemas.Attachment,
mongooseConnection: this.mongooseConnection,
});
this.attachmentRepository = this.attachmentGridFsRepository.model;
}
Test module constructor:
const module: TestingModule = await Test.createTestingModule({
imports: [
WinstonModule.forRoot({
transports: [
new transports.Console({
level: 'info',
handleExceptions: false,
format: format.combine(format.json()),
}),
],
}),
],
providers: [AttachmentsService, {
provide: getConnectionToken(''),
useValue: {},
}],
}).compile();
service = module.get<AttachmentsService>(AttachmentsService);
I realize that I will have to mock the connection object to be callable by GridFS, but right now I am unable to actually get the test module to build.