-
-
Save souparno/851536f64f03c68a2d55 to your computer and use it in GitHub Desktop.
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
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; |
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
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