How to get response's body with mocha / node.js -
i'm new mocha / omf. have basic test below:
omf('http://localhost:7000', function(client) { client.get('/apps', function(response){ response.has.statuscode(200); response.has.body('["test1","test2"]'); }); });
i'd check if value "test2" among list returned cannot figure out how feasible. i'm thinking of like:
omf('http://localhost:7000', function(client) { client.get('/apps', function(response){ response.has.statuscode(200); // response.body.split.contains("test2"); // }); });
can access response.body , parse string ?
** update **
i've tried test mocha, simple status code:
request = require("request"); describe('applications api', function(){ it('checks existence of test application', function(done){ request .get('http://localhost:7000/apps') .expect(200, done); }); });
but got next error:
typeerror: object # has no method 'expect'
any thought ? mocha need have additional addons ?
the sec illustration can not work shown. request.get asynchronous.
here's working illustration running request , should
request = require("request"); should = require("should"); describe('applications api', function() { it('checks existence of test application', function(done) { request.get('http://google.com', function(err, response, body) { response.statuscode.should.equal(200); body.should.include("i'm feeling lucky"); done(); }) }); });
node.js mocha
No comments:
Post a Comment