Skip to content

Commit

Permalink
Update Mongoose recipe
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Wubben <mark@novemberborn.net>
  • Loading branch information
puding-yum and novemberborn committed Oct 31, 2021
1 parent 7098eec commit 3a0d102
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions docs/recipes/endpoint-testing-with-mongoose.md
Expand Up @@ -51,13 +51,12 @@ const User = require('../models/User');
Next start the in-memory MongoDB instance and connect to Mongoose:

```js
// Start MongoDB instance
const mongod = new MongoMemoryServer()

// Create connection to Mongoose before tests are run
test.before(async () => {
const uri = await mongod.getUri();
await mongoose.connect(uri, {useMongoClient: true});
test.before(async t => {
// First start MongoDB instance
t.context.mongod = await MongoMemoryServer.create();
// And connect
await mongoose.connect(mongod.getUri());
});
```

Expand Down Expand Up @@ -117,8 +116,8 @@ Finally disconnect from and stop MongoDB when all tests are done:

```js
test.after.always(async () => {
mongoose.disconnect()
mongod.stop()
await mongoose.disconnect()
await t.context.mongod.stop()
})

```
Expand Down

0 comments on commit 3a0d102

Please sign in to comment.