node.js - Sinon.js: Correct way to stub and analyze the return -


i writing node app using coffeescript , doing tdd using mocha.js. please can point me correct way write test.

what want do: fake response of 'ra.do_get'and call method 'all_tests' analyze return value

var requestadapter = require('./request_adapter');  class queryhandler   constructor: (@adapter) ->     @klass  = "queryhandler"     @url    = "http://localhost:#{port[@adapter]}/"     logger.debug "[#{@klass}] creating .."     //requestadapter class doing get/post etc (using request npm)     @ra   = new requestadapter(@url)    all_tests: (cb) ->     logger.info "#{@adapter}: requesting test - #{adapter_apis.all_tests_session}"     _url = @url + adapter_apis.all_tests_session      @ra.do_get _url, (error , response) ->       if error         return cb({error: true, message: "#{@adapter} adapter errored out"})       else         return cb(null,response)     return    

thanks

finally worked. obj trying spy on wrong

describe('#all_tests()', function(){  it('should return tests', function(done){     var qh_obj = new qh("fake_adapter");    var spy    = sinon.spy(qh_obj.ra,'do_get');     qh_obj.all_tests(function(e,r) {});    (spy.callcount).should.equal(1);     done();   }); }); // describe 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -