Follow these steps to getting start:
$ git clone https://github.com/pedromdev/mongoose-jest-setup.git
$ cd mongoose-jest-setup
$ npm i
$ npm run test
To start the MongoDB memory server and connect to it with mongoose, you just need call MongooseConnection.open on beforeAll:
beforeAll(async () => {
await MongooseConnection.open()
});
And to stop the server and mongoose, call MongooseConnection.close on afterAll:
afterAll(async () => {
await MongooseConnection.close()
});