Skip to content

Instantly share code, notes, and snippets.

@davidecaruso
Last active March 26, 2020 18:45
Show Gist options
  • Save davidecaruso/11cdc338e6641905c5f811488b3e695d to your computer and use it in GitHub Desktop.
Save davidecaruso/11cdc338e6641905c5f811488b3e695d to your computer and use it in GitHub Desktop.
MongoDB Integration Tests
import mongoose from 'mongoose';
const connect = async () => {
await close();
await mongoose.connect(`${process.env.MONGODB_DATABASE}Test`, {
// Mongoose options
});
};
const clear = async () => {
await mongoose.connection.dropDatabase();
};
const close = async () => {
await mongoose.connection.close();
};
export default async ({before, afterEach, after}, callback: () => void) => {
await before(async () => await connect());
await afterEach(async () => await clear());
await after(async () => await close());
await callback();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment