NestJS - Mongoose @InjectConnection unit testing
When you do not add an explicit connection name, nest.js will use the default connection token DatabaseConnection
, which is defined as a constant by the nestjs-mongoose package:
export const DEFAULT_DB_CONNECTION = 'DatabaseConnection';
So you can use getConnectionToken('Database')
:
providers: [AttachmentsService, { provide: getConnectionToken('Database'), useValue: {},}]
Update 2019
The pull request was merged. You can now getConnectionToken()
.
I have created a pull request which lets getConnectionToken()
without any parameters return the default connection token.