New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing file download, res.files returns empty object #126
Comments
Not sure about the Dunno if there's a better way but looks like this is relevant: http://stackoverflow.com/questions/13573315/read-response-output-buffer-stream-with-supertest-superagent-on-node-js-server Using the strategy in that article, I was able to test the md5 of some random pdf on the internets: "use strict";
const chai = require("chai");
const chaiHttp = require("chai-http");
const md5 = require("md5");
const expect = chai.expect;
chai.use(chaiHttp);
const binaryParser = function (res, cb) {
res.setEncoding("binary");
res.data = "";
res.on("data", function (chunk) {
res.data += chunk;
});
res.on("end", function () {
cb(null, new Buffer(res.data, "binary"));
});
};
it("merp", function (done) {
chai
.request("www.cbu.edu.zm/downloads/")
.get("pdf-sample.pdf")
.buffer()
.parse(binaryParser)
.end(function (err, res) {
if (err) done(err);
expect(res).to.have.status(200);
expect(md5(res.body)).to.equal("fa7d7e650b2cec68f302b31ba28235d8");
done();
});
}); |
Thanks. I have updated the question on stackoverflow, based on your solution. |
meeber you saved my life. |
Originally asked here: http://stackoverflow.com/questions/40517088/using-mocha-chai-to-ensure-rest-api-serves-up-a-file/
I am wanting to download the response file in a test, but the req.files value is an empty object. Displays as
{}
when displayed with console. The superagent docs suggest thatres.files
should provide a file.Note the endpoint works when testing with 'wget'.
The code I am using for my test
Is there something I am missing?
The text was updated successfully, but these errors were encountered: