my server code has simple route in need send tiny thumbnail (jpeg) client display. here's sample of code:
router.get('/thumbnail/:title/',function(req,resp){ let title = req.params.title; getfilename(title).then(thumbnailcb,errorcb); function thumbnailcb(jpeg){ fs.readfile(jpegfile,sendjpegfile); } function sendjpegfile(err,data){ if ( err ) { fs.readfile(default_thumbnail,senddefault); } else { resp.send(data); } }; function senddefault(err,data){ if ( err ) {console.log(err);} else { resp.send(data); } }; function errorcb(error){ console.log(error); }; });
i trying test in mocha. first thought compare buffers, , apparently, not 1 think this: https://github.com/mochajs/mocha/issues/1624
so, not working. following mocha/chai code. mocha hangs on assert call. have suggestions on testing route?
it('should thumbnail title',function(done){ const default_thumbnail = /* default file */; const titlenotfound = /* random title */; request(app) .get(url + '/thumbnail/' + titlenotfound) .expect(200) .expect('content-type','application/octet-stream') .end(function(err,res){ fs.readfile(default_thumbnail,'utf-8',function(err,data){ if(err){done(err);} assert(data.tostring(),res.text.tostring()); // no bueno done(); }); }); });
Comments
Post a Comment