Skip to content

Instantly share code, notes, and snippets.

@souparno
Forked from marcusoftnet/getApp.js
Last active August 29, 2015 14:11
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 souparno/851536f64f03c68a2d55 to your computer and use it in GitHub Desktop.
Save souparno/851536f64f03c68a2d55 to your computer and use it in GitHub Desktop.
var app = require("express")();
app.get('/user', function(req, res){
res.send(200, { name: 'marcus' });
});
// In order to reach the app from other modules
// we need to export the express application
module.exports.getApp = app;
var request = require('supertest');
// Here we get hold of the express application
// by using the exported 'getApp'-property
var app = require("./getApp").getApp;
describe('GET /users', function(){
it('respond with json', function(done){
// the request-object is the supertest top level api
request(app)
.get('/user')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, done); // note that we're passing the done as parameter to the expect
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment