testing下载是否成功与超级

我正在用超级testing我的API端点,它工作的很好,但我不知道如何testing文件下载是否成功。

在我的路线文件中,我已经定义了端点:

app.get('/api/attachment/:id/file', attachment.getFile); 

和函数getFile()看起来像这样:

 exports.getFile = function(req, res, next) { Attachment.getById(req.params.id, function(err, att) { [...] if (att) { console.log('File found!'); return res.download(att.getPath(), att.name); } 

然后,在我的testing文件中,我尝试以下内容:

 describe('when trying to download file', function() { it('should respond with "200 OK"', function(done) { request(url) .get('/api/attachment/' + attachment._id + '/file'); .expect(200) .end(function(err, res) { if (err) { return done(err); } return done(); }); }); }); 

我知道确定该文件被find,因为它注销了File found! 。 它也工作正常,如果我尝试手动,但由于某种原因,摩卡返回Error: expected 200 "OK", got 404 "Not Found"

我已经尝试了不同的mimetypes和supertest .set("Accept-Encoding": "*") ,但没有任何作用。

有人知道怎么做吗?

这个问题在库中已经被修复,或者你的代码的其他部分有一个bug。 你的例子运行良好,并给予

  when trying to download file File found! ✓ should respond with "200 OK"