Skip to content

Instantly share code, notes, and snippets.

@Lazhari
Created July 17, 2015 06:20
Show Gist options
  • Save Lazhari/fcdeb86a07980f9b356e to your computer and use it in GitHub Desktop.
Save Lazhari/fcdeb86a07980f9b356e to your computer and use it in GitHub Desktop.
Write a unit testing for a RestFul api Expressjs using mocha and superagent
var superagent = require('superagent');
var expect = require('expect.js');
describe('express rest api server', function(){
var id
it('posts an object', function(done){
superagent.post('http://localhost:3000/user/test')
.send({
name: 'Med',
email: 'med@gistbox.com'
})
.end(function(e,res){
// console.log(res.body)
expect(e).to.eql(null)
expect(res.body.length).to.eql(1)
expect(res.body[0]._id.length).to.eql(24)
id = res.body[0]._id
done()
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment