Skip to content

Add docs for endpoint testing with mongoose #1420

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

Merged
merged 15 commits into from
Sep 2, 2017
8 changes: 4 additions & 4 deletions docs/recipes/endpoint-testing-with-mongoose.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Next start the in-memory MongoDB instance and connect to Mongoose:
const mongod = new MongodbMemoryServer()

// Create connection to Mongoose before tests are run
test.before(async t => {
test.before(async () => {
const uri = await mongod.getConnectionString();
await mongoose.connect(uri, {useMongoClient: true});
});
Expand All @@ -64,7 +64,7 @@ When you run your first test, MongoDB downloads the latest MongoDB binaries. The
You'll want to populate your database with dummy data. Here's an example:

```js
test.beforeEach(async t => {
test.beforeEach(async () => {
const user = new User({
email: '[email protected]',
name: 'One'
Expand All @@ -76,7 +76,7 @@ test.beforeEach(async t => {
Dummy data should be cleared after each test:

```js
test.afterEach.always(async t => await User.remove());
test.afterEach.always(async () => await User.remove());

Choose a reason for hiding this comment

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

async and await are redundant here since you're returning a Promise from User.remove().

Copy link
Member

Choose a reason for hiding this comment

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

The explicitness doesn't hurt I think.

Choose a reason for hiding this comment

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

There's no need for it and anyone using xo will need to remove it if they copy+paste. Better to just remove it and set an example by only shipping code that's linted even if it's only in the docs.

```

Now you can use SuperTest to send off a request for your app endpoint. Use AVA for your assertions:
Expand Down Expand Up @@ -114,7 +114,7 @@ test.serial('litmus create user', async t => {
Finally disconnect from and stop MongoDB when all tests are done:

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