سؤال

I learn testing with konacha. I would like to test some coffee file:

class Downloader
 constructor: ->

 loadData: (data) ->

 populate: (data) =>
   @loadData(something)

I don't know how to stub loadData method to return model. I mean when I call Downloader.populate int test I wish the method loadData return stubed model. Thanks for all answers.

هل كانت مفيدة؟

المحلول

You should stub loadData to return the stubbed model.

it 'returns stubbed model', ->
    sinon.stub(Downloader.prototype, 'loadData').returns(stubbedModel)

    d = new Downloader()
    d.populate().should.equal stubbedModel
    d.loadData.calledOnce.should.be.true

    Downloader.prototype.loadData.restore()
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top