Skip to content

Instantly share code, notes, and snippets.

@gabhi
Created April 3, 2014 17:47
Show Gist options
  • Save gabhi/9959221 to your computer and use it in GitHub Desktop.
Save gabhi/9959221 to your computer and use it in GitHub Desktop.
Sample test case to test POST method for express js REST API
//Following test case assumes you have express js server running at port 5000 and has api /api/login
var should = require('should');
var assert = require('assert');
var request = require('supertest');
var winston = require('winston');
describe('Routing', function() {
var url = 'http://localhost:5000';
before(function(done) {
// In our tests we use the test db
done();
});
describe('REST Api', function() {
it('should return valid AuthId', function(done) {
var params = {
username: 'test',
password: 'password',
};
request(url)
.post('/api/login')
.send(params)
// end handles the response
.end(function(err, res) {
if (err) {
throw err;
}
res.should.have.status(200);
res.body.should.have.property('AuthId');
done();
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment