how can use mocha.js , should.js test express.js app sending correct data back?
the reason ask sometimes, if req.xhr
send same data in different format, depending on extension route. so, reason want ensure routes performing right conditions under circumstances given.
is there way can express send result can read should.js?
you can use mocha , request end-to-end http testing. here's example, app.js runs server:
process.env.node_tls_reject_unauthorized = '0'; // avoids depth_zero_self_signed_cert error self-signed certs var request = require('request').defaults({ encoding: null }); var fs = require('fs'); var expect = require('expect.js'); var app = require("../../app.js"); var hash = function (file) { crypto.createhash('sha1').update(file).digest('hex') }; describe('static tests', function () { it('should serve out correct favicon', function (done) { var favicon = fs.readfilesync(__dirname + '/../../../public/img/favicon.ico'); request.get('https://localhost:' + process.env.port + '/favicon.ico', function (err, res, body) { expect(res.statuscode).to.be(200); expect(hash(body)).to.be(hash(favicon)); done(); }); }); });
Comments
Post a Comment