Question

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.

Was it helpful?

Solution

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top