【发布时间】:2017-07-12 23:56:21
【问题描述】:
假设我有这个简单的代码:
var https = require('https');
var options = {
host: 'openshift.redhat.com',
port: 443,
path: '/broker/rest/api',
method: 'GET'
};
var req = https.request(options, function(response) {
console.log(response.statusCode);
response.pipe(save stream to file with fs)
});
req.on('error', function(e) {
console.error(e);
});
req.end();
好吧,我对 sinon.js 有点陌生,我想问一下:如何存根 response.pipe()? 当然,我可以为 https.request 制作存根并使用 .on 和 .end 返回一些东西,这很容易,但我不知道如何测试 response.pipe() 是否被正确的参数调用......(nodejs文档说响应是回调) 在这种情况下,文档没有帮助! ofc 测试环境是 mocha,也可以使用 chai 请给我一些建议或例子。 谢谢,马特
【问题讨论】:
标签: javascript node.js unit-testing httprequest sinon