Skip to content

Instantly share code, notes, and snippets.

@jpedroschmitz
Created November 18, 2019 23:14
Show Gist options
  • Save jpedroschmitz/5f146604535176eec17fa5447e9e47d8 to your computer and use it in GitHub Desktop.
Save jpedroschmitz/5f146604535176eec17fa5447e9e47d8 to your computer and use it in GitHub Desktop.
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