How to use Jest to mock and spy a `mongoose.connect` in a provider of NestJS
问题 I defined a custom database-specific Module to connect a MongoDB via Mongoose APIs. The complete code is here. { provide: DATABASE_CONNECTION, useFactory: (dbConfig: ConfigType<typeof mongodbConfig>): Connection => createConnection(dbConfig.uri, { useNewUrlParser: true, useUnifiedTopology: true, //see: https://mongoosejs.com/docs/deprecations.html#findandmodify useFindAndModify: false }), inject: [mongodbConfig.KEY], }, When writing tests for this provider, I want to confirm the database