Created
July 17, 2015 06:20
-
-
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
This file contains 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 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: '[email protected]' | |
}) | |
.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