Skip to content

Instantly share code, notes, and snippets.

@yattias
Created October 19, 2017 21:11
Show Gist options
  • Save yattias/62ec1cd0233617901824aa14649037bf to your computer and use it in GitHub Desktop.
Save yattias/62ec1cd0233617901824aa14649037bf to your computer and use it in GitHub Desktop.
// Drops all mongo collections associated with a test Database before running any tests.
process.env.NODE_ENV = 'test';
import mongoose from 'mongoose';
import settings from '../../src/config/settings';
before(async function(){
const dropCollection = (name) => {
return new Promise(function(resolve, reject){
mongoose.connection.collections[name].drop(function(err){
resolve();
});
});
}
const collectionNames = Object.keys(mongoose.connection.collections);
let currentCollection;
for (let i = 0; i < collectionNames.length; i++) {
currentCollection = collectionNames[i];
await dropCollection(currentCollection);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment