Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Mongoose recipe #2878

Merged
merged 3 commits into from Oct 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got error when directly call mongod to get Uri. I think it should be t.context.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 () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here I think I should add t as parameter ?

mongoose.disconnect()
mongod.stop()
await mongoose.disconnect()
await t.context.mongod.stop()
})

```
Expand Down