Last active
March 26, 2020 18:45
-
-
Save davidecaruso/11cdc338e6641905c5f811488b3e695d to your computer and use it in GitHub Desktop.
MongoDB Integration Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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