在异步系列中存根api请求

时间:2015-05-05 14:17:37

标签: node.js testing sinon

我有一个模块使用imageResizer和另一个模块graphicsmagick调整图像大小apiCaller,该模块有两个函数,一个用于get请求,另一个用于post请求对于request请求,请使用imageResizer模块。 在apiCaller.get我调用apiCaller.post时,如果获取请求成功,则调用触发图像大小调整的函数,然后调用exports.imageResizer = function (arguments) { async.series([ function(callback) { apiCaller.get(callback); }, function(callback) { gm("filepath") .resize("sizes") .write("destinationPath", function (err) { if(err) // do something }, callback()); }, function(callback) { apiCallerPost(arguments) } ]); } 。{/ p>

有些事情是这样的:

apiCaller = {};

apiCaller.get = function (arguments, callback) {
   // setup variables and stuff
   function _callback (error, response, body) {
     if (error) {// do somethind}
     else {callback(null, body}
   }

   request.get(options, _callback);
}

module.exports = apiCaller;
apiCaller.get

我的问题是哪种测试方法最好? 将apiCaller.postrequest作为最佳方法? sinon模块本身怎么样?那还需要存根吗?

我正在使用chaimochaproxyquirepublic class FakeClass : IGettProxy { public Task<List<CityDetails>> getCity(){ // here goes your fake implementation, to be injected on your controller. } // Remember to implement the other method }

0 个答案:

没有答案