Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let mongoServer;
beforeAll(async () => {
mongoServer = new MongoMemoryServer();
const URI = await mongoServer.getUri();
mongoose.connect(URI, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
});
});
afterAll(async done => {
mongoose.disconnect(done);
await mongoServer.stop();
});
afterEach(async () => {
const collections = await mongoose.connection.db.collections();
for (let collection of collections) {
await collection.deleteMany();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment