This is one thing that I like about Node.js / Javascript, making this kind of thing easy as soon as you hang it.
In short, you run your server code and then actually use Request or a super agent to make these HTTP requests. I personally prefer Superagent because of its automatic JSON encoding, but be careful, documents are outdated and incorrect, YMMV. Most people choose a request.
A simple mocha example using a query:
describe('My Server', function(){ describe('GET /users', function(){ it("should respond with a list of users", function(done){ request('http://mytesturl.com/users', function(err,resp,body){ assert(!err); myuserlist = JSON.parse(body); assert(myuserlist.length, 12); done(); }); }); }); });
Hope this helps. Here is an example of my Mocha test (CoffeeScript) using this style with detailed examples: https://github.com/jprichardson/logmeup-server/blob/develop/test/integration/app.test.coffee Oh, I also use Superagent.
JP Richardson
source share