如何将@ ra.do_post存根以便进入“第2步”
滚动到结尾,看看我在做什么。提前致谢了
RA = require('./request_adapter')
class QueryHandler
constructor: (@adapter) ->
@ra = new RA()
create_test: (id, data, cb) ->
self = this
_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? and 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"})
这是我在规范中尝试的内容
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();
});
答案 0 :(得分:0)
我的坏,我的规格有误。
var fn = function(a,b,ccb){
ccb(undefined, true);
};
stub = sinon.stub(qh_obj.ra,'do_post', fn)