Skip to content

Instantly share code, notes, and snippets.

@ivoputzer
Last active September 2, 2015 23:23
Show Gist options
  • Save ivoputzer/63150aa7ffb79ccd5eca to your computer and use it in GitHub Desktop.
Save ivoputzer/63150aa7ffb79ccd5eca to your computer and use it in GitHub Desktop.
express4.router isolation testing
# app/app.coffee
express = require 'express'
app = express()
app.use require 'controllers/status'
app.listen(80)
# app/controllers/status.coffee
express = require 'express'
module.exports = exports = express.Router()
exports.get '/status', (req, res) ->
res.json status: 'available', timestamp: new Date().toISOString()
# app/spec/controllers/status.spec.coffee
chai = require('chai')
expect = chai.expect
describe 'controllers', ->
# ...
describe 'status', ->
@controller = require.main.require 'app/controllers/status'
it 'responds with available and timestamp if everything is up and running', (done) =>
async_expectations = (data) ->
expect(data?.status).to.eq 'available'
done()
@controller.handle {url: '/status', method: 'get'}, {json: async_expectations}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment