javascript - sinon.js stub - How to stub async.map -


i want test following function.

var myfun = function (a, b, callback) {    async.map(a, function (b, mapcallback) {       //do b => code don't want execute        mapcallback(null, res)     },     function (err, output) {         if (err) {             logger.error(err);             return callback(err, null);         }         return callback(null,  output.filter(function(n){ return n != null }));     }); } 

here using async.map, want stub. async.map takes 3 parameters, first array , second , third callback. want stub second callback , call third callback test values. how it?

i tried:

var mockasync = sinon.stub(async, "map") mockasync.yields("some error", null); 

but executes second function , not third function, tried using callsarg, did not help, not sure relevant here or not.

see in sinon docs

stub.callarg(argnum) stub.callargwith(argnum, [arg1, arg2, ...]) 

in context should be

mockasync.callargwith(1, "some error", null) 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -