node.js - Asyncjs Waterfall and SinonJS stub -


  • how can stub @ra.do_post goes "step 2"

    • right when run spec inside async.waterfall after step1 goes step 5
    • what think in spec not returning callback go step2

scroll end see doing. bunch in advance

ra = require('./request_adapter')  class queryhandler   constructor: (@adapter) ->     @ra = new ra()     create_test: (id, data, cb) ->     self =      _url    =  url + adapter_apis.create     bll_url = "http://localhost:" + 11 + "/" + bll_apis.pkg_switch        async.waterfall [       (done) ->         console.info("step 1 ==================")         @ra.do_post some_url, data, done        , (resp, done) ->         console.info("step 2 ==================")         console.info(resp)         if resp? , resp.status isnt "success"           console.info("step 3a ==================")           cb({error: true, message: "error."})         else           console.info("step 3b ==================")           fn = () -> self.ra.do_post _url, data , done           helper.delay 500, fn        , (resp, done) ->         console.info("step 4 ==================")         cb(null,resp)      ], (error, resp) ->       console.info("step 5 ==================")       if error         cb({error: true, message: "errored out"}) 

this tried in spec

  var qh      = require(query_handler");   var qh_obj  = new qh("fake");    var fn = function(ccb){     ccb(undefined, 10);   };    stub = sinon.stub(qh_obj.ra,'do_post').returns(fn);    qh_obj.create_test("fake_id", {switch_data: {a: 11}}, function(e,r) {     console.log(e);     (e.error).should.be.true     done();   }); 

my bad, had mistake in spec.

var fn = function(a,b,ccb){     ccb(undefined, true);   };    stub = sinon.stub(qh_obj.ra,'do_post', fn) 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -