Last active
September 2, 2015 23:23
-
-
Save ivoputzer/63150aa7ffb79ccd5eca to your computer and use it in GitHub Desktop.
express4.router isolation testing
This file contains 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
# app/app.coffee | |
express = require 'express' | |
app = express() | |
app.use require 'controllers/status' | |
app.listen(80) |
This file contains 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
# 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() |
This file contains 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
# 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