-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b1d03e0
Add docs for endpont testing with mongoose
zellwk fb1440a
update
zellwk bc0fb07
update
zellwk 51f2666
add note for removeFixtures
zellwk 9ad076f
update
zellwk 8b7ccba
update endpoint recipe
zellwk b0790d1
update docs
zellwk 5249510
update
zellwk 4ff2f9b
update recipe
zellwk ab27af2
remove Mongoose from Mongodb docs
zellwk a99b8c1
update with better explaination
zellwk 85f0ee9
Edit copy
novemberborn 605086d
Change 'Mongoose ODM' back to 'Mongoose'
novemberborn fa7ac39
Remove unnecessary t parameter from hook implementations
novemberborn 60405b5
Remove redundant async-await
novemberborn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}); | ||
}); | ||
|
@@ -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' | ||
|
@@ -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()); | ||
``` | ||
|
||
Now you can use SuperTest to send off a request for your app endpoint. Use AVA for your assertions: | ||
|
@@ -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() | ||
}) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async
andawait
are redundant here since you're returning aPromise
fromUser.remove()
.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.