Closed MTschannett closed 4 years ago
Any update on this issue?
How about using this instead: https://github.com/nodkz/mongodb-memory-server
Looks like mockgoose is abandoned. mongodb-memory-server looks more recent and, imho, mature from what I read in the docs.
This sounds like a great option. I guess adding mocked data is also easy.
It should be very easy to use https://github.com/nodkz/mongodb-memory-server together with the existing MongooseModule
using Async Configuration feature I believe.
This works:
@Module({
imports: [
MongooseModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
const mongod = new MongoMemoryServer();
const uri = await mongod.getConnectionString();
return {
uri: uri
}
},
inject: [ConfigService],
}),
],
})
export class TestDatabaseModule {}
It seems that the above solution should be sufficient for all use-cases. Thanks for sharing!
So after opening the issue in the wrong repository, here I'm again.
I'm submitting a...
Current behavior
Testing e2e with mongoose is done via mockgoose. A connection has to be created, injected as provider (in AppModule) Also models cannot be registered with the
mongoose.forFeature()
-method, which is very convenient. Im refering to this part of the documentation (https://docs.nestjs.com/recipes/mockgoose)Expected behavior
It would be nice to get a TestingModule which can be used in e2e tests to mock the
mongoose.forRoot()
-method. Something like the HttpClientTestingModule from angular. Also it would be great if there would be a way to add fake data, when creating the connection to the mocked database.Minimal reproduction of the problem with instructions
-
What is the motivation / use case for changing the behavior?
Currently it is cumbersome to setup a mongodb connection (either over mockgoose or a other collection in the database). It would be very convenient to have a built-in way to setup a connection which works together with the other parts of the mongoose package.
Environment
-