dimanche 29 mai 2016

How to functional/unit test file download in Javascript NodeJS-ExpressJS

In my NodeJS ExpressJS application, I have an API that I consume to convert to a CSV file and subsequently download it on the client like so:

res.setHeader('Content-Type', 'application/octet-stream');
res.setHeader('Content-Disposition', 'attachment; filename=BuyNowOrders.csv;');
res.end(csv, 'binary');

I have Mocha/Sinon/NighwatchJS test suite that I use for unit testing as well as functional testing with a full-fledged mock-api server module that serves up mock data.

My question is - how do I test this functionality? Normally I do functional testing testing and unit testing for each module.

I have so far written tests for the Download button to be present on the page, but am not sure how to test whether the file has been downloaded.

Aucun commentaire:

Enregistrer un commentaire