There is just one test case that I’m testing. I verified the MongoDB methods and they seem to be up to
date. No open issues on GitHub as well.
Error: at MongoMemoryServer.getUri (node_modules/mongodb-memory-server-
core/src/MongoMemoryServer.ts:706:15)
at src/test/setup.ts:7:32
at src/test/setup.ts:8:71
at Object.<anonymous>.__awaiter (src/test/setup.ts:4:12)
at Object.<anonymous> (src/test/setup.ts:5:22)
import { MongoMemoryServer } from "mongodb-memory-server";
import mongoose from "mongoose";
let mongo: any;
beforeAll(async () => {
mongo = new MongoMemoryServer();
const mongoUri = await mongo.getUri();
await mongoose.connect(mongoUri);
});
beforeEach(async () => {
const collections = await mongoose.connection.db.collections();
for (let collection of collections) {
await collection.deleteMany({});
}
});
afterAll(async () => {
await mongo.stop();
await mongoose.connection.close();
});
3
Answers
channge the line
mongo = new MongoMemoryServer();
tomongo = await MongoMemoryServer.create()
I had your same issue and by looking at the documentation I figure out that you first have to create the object with
new
and then start the instance with start():You have 2 options to solve this problem:
1- Change the line:
to:
2- Change the lines:
To: