Skip to content

Instantly share code, notes, and snippets.

@evanshortiss
Last active November 13, 2018 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanshortiss/ea9e18f5e0f75bf52a4ea68fdd2ae7eb to your computer and use it in GitHub Desktop.
Save evanshortiss/ea9e18f5e0f75bf52a4ea68fdd2ae7eb to your computer and use it in GitHub Desktop.
const supertest = require('supertest')
const express = require('express')
const router = require('lib/routes/some-router')
describe('#some-router tests', () => {
// temp express app. allows to tests routes in isolation from broader application
const app = express()
// app.use(router()) or whatever way works for your structure
app.use('/stuff', router)
it('should return a 400 error', (done) => {
const request = supertest(app)
const itemId = 10
request.get(`/stuff/items/${itemId}`)
.expect('Content-Type', /json/)
.expect(400)
.end(function(err, res) {
if (err) {
done(err)
}
// more assertions?
done()
});
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment