Skip to content

Instantly share code, notes, and snippets.

@Madhuka
Created November 14, 2013 07:03
Show Gist options
  • Save Madhuka/7462637 to your computer and use it in GitHub Desktop.
Save Madhuka/7462637 to your computer and use it in GitHub Desktop.
mocha test file for REST api
var request = require('superagent');
var expect = require('expect.js');
var express = require('express');
// 'express' is used in bodyParser if needed
describe('Suite one - #REST API test', function() {
var name = 'jhon';
it('- GET is testing', function(done) {
request.get('http://localhost:9763/jaggeryApp/').end(function(res) {
expect(res).to.exist
expect(res.status).to.equal(200);
expect(res.text).to.contain('testing API');
expect(res.type).to.contain('text');
expect(res.header.hasOwnProperty('customheader')).to.equal(true);
//console.log(res); //can be used log in mocha
done();
});
});
it('- POST is testing', function(done) {
request.post('http://localhost:9763/jaggeryApp/?name=' + name).send().end(function(e, res) {
//console.log(res.text)
expect(e).to.eql(null)
expect(res.text).to.contain(name);
done()
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment