【发布时间】:2017-03-23 20:39:17
【问题描述】:
我想验证对我的 REST API 端点之一的调用是否正在提供文件,但我不知道该怎么做,也没有看到任何示例?我确实看过documentation,但这对我没有多大帮助。
服务器端代码本质上是这样做的(在 Express 中):
handleRetrieveContent(req, res, next) {
const filepaht = '...';
res.sendFile(filepath)
}
和测试用例:
it('Should get a file', (done) => {
chai.request(url)
.get('/api/exercise/1?token=' + token)
.end(function(err, res) {
if (err) { done(err); }
res.should.have.status(200);
// Not sure what the test here should be?
res.should.be.json;
// TODO get access to saved file and do tests on it
});
});
我基本上想做以下测试:
- 确保响应是文件
- 确保文件内容有效(校验和测试)
任何帮助将不胜感激。
【问题讨论】:
标签: node.js rest express integration-testing chai